C#调用c++dll中 函数带指针参数方法

c++ 代码片段:
BOOL GetLineAt(int nIndex,CHAR* name,int &vertexCount);
C# 中如何写呢 ?
[DllImport("GDZYStar.dll")]
public static extern bool GetPointAtx(int nIndex,CHAR* name,int &vertexCount); CHAR* name,int &vertexCount这两个参数怎么转换啊

第1个回答  推荐于2017-09-18
CHAR* 可以先实例化一个StringBuilder然后可以传给char*类型
关于其他的请参考msdn中的c++与c#的类型转换
对应关系如下:
C++ ---- C#
传入的char* ----string
传出的char* ---- StringBuilder(预分配空间)
short ----short
char ---- byte
char[n] ---- fixed byte[n]
结构指针 ----结构指针
函数指针 ---- 委托本回答被提问者采纳
第2个回答  推荐于2017-09-23
CHAR* 可以先实例化一个StringBuilder然后可以传给char*类型
关于其他的请参考msdn中的c++与c#的类型转换
对应关系如下:
C++ ---- C#
传入的char* ----string
传出的char* ---- StringBuilder(预分配空间)
short ----short
char ---- byte
char[n] ---- fixed byte[n]
结构指针 ----结构指针
函数指针 ---- 委托
里面涉及到函数指针,在C#里面用委托替代,总的代码如下:

delegate int pfunc(void* dst,void* src,int nSize);
unsafe public struct MyStruct
{
public Byte* pMemory;//也可以用unsinged int替代(uint*)
public pfunc myfunc;//这里用委托替代函数指针
public char[] rd;//声明的时候不能指定大小,可以在new的时候指定大小
}
相似回答