封送c++结构体作为c#中的引用
本文关键字:引用 c++ 结构体 封送 | 更新日期: 2023-09-27 18:16:54
我正在尝试将这个结构体从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.
任何想法?
试试这个:
[StructLayout(LayoutKind.Sequential), Serializable]
public struct ListOfObjects
{
public int id;
[MarshalAs(UnmanagedType.LPStr)]
public string name;
}