我想從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聲明。我們無法猜測它。 –