最近在编写C#上位机应用程序,需要调用C++的dll,期间遇到dll接口库中char*类型纠结了很久,试过string,StringBuilder,StringBuilder结果都以失败告终,通过查找博客等资料最后找到了救命稻草---IntPtr。例子如下:
C++dll接口函数:
void JT_ReaderVersion(int icomID,char* szReaderVersion,int iRVerMaxLength char* szAPIVersion, int iAPIVerMaxLength);
szReaderVersion和 szAPIVersion参数作为输出参数需要返回其所在地址上的字符串内容。
C#调用该接口函数声明:
[DllImport("JKT135_SD.dll",CharSet=CharSet.Ansi)]
//①public static extern void JT_ReaderVersion(int iComID, ref StringBuilder szReaderVersion, int iRVerMaxLength, ref StringBuilder szAPIVersion, int iAPIVerMaxLength);
//②public static extern void JT_ReaderVersion(int iComID, ref Byte[] szReaderVersion, int iRVerMaxLength, ref Byte[] szAPIVersion, int iAPIVerMaxLength);
//③public static extern void JT