我的 C++ 应用程序中有这个结构:
struct Animation
{
UINT To;
UINT From;
USHORT AnimationID;
};
struct Entity
{
USHORT X, Y;
UINT SERIAL;
USHORT SpriteID;
BYTE DIRECTION;
USHORT TYPE;
BOOL Cursed;
BOOL Fased;
BOOL IsPet;
void AddAnimation(Animation &const a)
{
Animations.push_back(a);
}
void ClearAnimations()
{
this->Animations.clear();
}
private:
vector<Animation> Animations;
};
我有这个导出的功能:
extern "C" __declspec(dllexport) Entity GetNearest(void)
{
Entity & result = GetNearestEntity();
return result;
}
是否可以使用它并在 c# 中获取实体值?
我试图这样做:
[DllImport("FatBoy.dll", SetLastError = true)]
internal static extern Entity GetNearest();
public struct Entity
{
ushort X, Y;
uint SERIAL;
ushort SpriteID;
byte DIRECTION;
ushort TYPE;
bool Cursed;
bool Fased;
bool IsPet;
}
当我调用它时,我得到了错误:
Method's type signature is not PInvoke compatible.