我想从C++这个结构复制到C#:元帅C++结构在C#参考
typedef struct
{
int id;
char *name;
} *ListOfObjects;
我一直在使用这种尝试,但它不是在应用程序中正确导入目前正使用该DLL和期待为特定的签名。
[StructLayout(LayoutKind.Sequential), Serializable]
public struct ListOfObjects {
[MarshalAsAttribute(UnmanagedType.ByValArray)]
public int id;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 15)]
public string name;
}
[DllExport("ReadListOfObjects", CallingConvention = CallingConvention.Cdecl)]
static ListOfObjects ReadListOfObjects()
{
ListOfObjects lists = new ListOfObjects();
return lists;
}
我编译DLL,然后尝试启动导入真实这些功能它给这个错误的程序之后:
The prodedure entry point ReadListOfObjects could not be located in the dynamic link library thedll.dll.
任何想法?
的的MarshalAs属性是严重错误的。但是你还没有接近它,它还找不到这个功能。您只显示结构,而不显示ReadListOfObjects()函数的C声明。我们无法猜测它。 –