gpt4 book ai didi

C#:指向结构内部结构的指针

转载 作者:行者123 更新时间:2023-11-30 22:49:25 24 4
gpt4 key购买 nike

我正在尝试在 C# 中使用编码。在 C++ 中,我有一个这样的结构:

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;
}

因此,C# 等效项是:

[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;
}

但是这个结构上的很多东西都是托管的(aiNode、aiMesh、aiLight)等等。所以,我有这个错误:

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

关于如何解决这个问题有什么想法吗?

最佳答案

这可能会变得非常复杂,具体取决于您要执行的操作。但是,在您工作时,它可以帮助您像这样在 C# 代码中声明每个指针。它使用 very useful IntPtr, which was described on here earlier today . :)

请注意,这不会神奇地让您的代码正常工作。在我可以就此向您提供意见之前,我需要了解更多正在发生的事情。

public struct aiScene
{
public uint Flags;
public IntPtr RootNode;
...
}

关于C#:指向结构内部结构的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1149087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com