c#调用c++库函数参数类型转换.docxVIP

  • 5
  • 0
  • 约1.55千字
  • 约 3页
  • 2021-11-08 发布于江苏
  • 举报
handle IntPtr hwnd IntPtr char * string int * -----------ref int int -----------ref int void * IntPtr unsigned char *-----ref byte Struct 需要在C#里重新定义一个Struct CallBack 回调函数需要封装在一个委托里,delegate static extern int FunCallBack(string str); 注意在每个函数的前面加上 public static extern +返回的数据类型,如果不加 public ,函数默认为私有函数,调用就会出错。 在 C#调用C++ DLL 封装库时会出现两个问题: 数据类型转换问题 指针或地址参数传送问题 首先是数据类型转换问题。因为 C#是.NET 语言,利用的是.NET 的基本数据类型,所以实际上是将 C++的数据类型与.NET 的基本数据类型进行对应。 例如 C++的原有函数是: int stdcall FunctionName(unsigned char param1, unsigned short param2 ) 其中的参数数据类型在 C#中,必须转为对应的数据类型。如: [DllImport(“ COM DLL path/file ”)] extern static int

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档