tags:

views:

676

answers:

1

I am trying to use marshalling in C#. In C++ I have a this struct:

struct aiScene
{
    unsigned int mFlags;
    C_STRUCT aiNode* mRootNode;
    unsigned int mNumMeshes;
    C_STRUCT aiMesh** mMeshes;
    unsigned int mNumMaterials;
    C_STRUCT aiMaterial** mMaterials;
    unsigned int mNumAnimations; 
    C_STRUCT aiAnimation** mAnimations;
    unsigned int mNumTextures;
    C_STRUCT aiTexture** mTextures;
    unsigned int mNumLights;
    C_STRUCT aiLight** mLights;
    unsigned int mNumCameras;
    C_STRUCT aiCamera** mCameras;
}

So, C# eqvivalent is:

[StructLayout(LayoutKind.Sequential)]
public struct aiScene
{
    public uint mFlags;
    public unsafe aiNode* mRootNode;
    public uint mNumMeshes;
    public unsafe aiMesh** mMeshes;
    public uint mNumMaterials;
    public unsafe aiMaterial** mMaterials;
    public uint mNumAnimations;
    public unsafe aiAnimation** mAnimations;
    public uint mNumTextures;
    public unsafe aiTexture** mTextures;
    public uint mNumLights;
    public unsafe aiLight** mLights;
    public uint mNumCameras;
    public unsafe aiCamera** mCameras;
}

But many on this structs are managed ( aiNode, aiMesh, aiLight ) etc. So, I have this error:

Cannot take the address of, get the size of, or declare a pointer to a managed type ('Assimp.aiNode')

Any ideas on how to solve this issue?

+3  A: 

This could get very complicated depending on what you are trying to do. However, as you are working it could help you do declare each of the pointers in the C# code like this. It uses the very useful IntPtr, which was described on here earlier today. :)

Please note that this will not magically get your code to work. I'd need to see a lot more of what's going on before I could give you input on that.

public struct aiScene
{
    public uint Flags;
    public IntPtr RootNode;
    ...
}
280Z28
Господи, что за изврат...лучше взять C++\CLI. Большое спасибо за ответ!