最近再用C#写一个工具,然后有调用到第三方C++写的动态链接库,然后动态链接库里面有个接口需要传入一个 结构体 指针,然后我在C#端 定义一个与之一样的 结构然后传进,但是编译运行调试的时候会报错,肯能是我的C# 端定义的结构体 跟 C++的 数据结构 数据类型不匹配导致的,但是我对 C# Marshal这个类不太熟悉,不知自己哪里数据类型写错了,请各位大家帮忙看看
C#结构体
public delegate void CallbackRecord(IntPtr param, byte[] tagName);
public delegate void CallbackInfo(IntPtr param, byte[] info);
public delegate void CallbackInfoValue(IntPtr param, byte[] info, byte[] value);
public delegate void CallbackInfoValueLimit(IntPtr param, byte[] info, double value, double upLimit, double lowLimit);
public delegate int CallbackStop(IntPtr param);
[StructLayout(LayoutKind.Sequential)]
public struct CallbackParam
{
IntPtr saveFunctionRecord;
IntPtr showNormalInfomation;
IntPtr showFailInfomation;
IntPtr showDebugInfomation;
IntPtr uploadStringValue;
IntPtr uploadDoubleValue;
IntPtr stopWhenNeed;
IntPtr callbackFunctionReservel;
IntPtr callbackFunctionReserve2;
IntPtr callbackFunctionReserve3;
IntPtr param;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] logPath;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] sn;
IntPtr record;
IntPtr paramReserve1;
IntPtr paramReserve2;
IntPtr paramReserve3;
}
C++结构
using CallbackInfo = void(void* param, const char* info);
using CallbackInfoValue = void(void* param, const char* info, const char* value);
using CallbackInfoValueLimit = void(void* param, const char* info, double value, double upLimit, double lowLimit);
using CallbackStop = int(void* param); // 当外部需要停止时此函数返回-1,当外部不需要停止时次函数返回0
struct CallbackParam {
CallbackInfo* saveFunctionRecord;
CallbackInfo* showNormalInformation;
CallbackInfo* showFailInformation;
CallbackInfo* showDebugInformation;
CallbackInfoValue* uploadStringValue;
CallbackInfoValueLimit* uploadDoubleValue;
CallbackStop* stopWhenNeed;
void* callbackFunctionReserve1;
void* callbackFunctionReserve2;
void* callbackFunctionReserve3;
void* param;
char* logPath;
char* sn;
void* record;
void* paramReserve1;
void* paramReserve2;
void* paramReserve3;
};