C++:
初始化窗口函数:
MYESLIB_API bool Start_Eslib(void *param,int locport,int reconn_delay,int maxcount);
回调函数结构体:
typedef struct
{
//1. *sender:发送窗口
//2. receid:接警机编号1-10:RS232串口1-串口10;11:UDP端口。范围一定在1-11
//3. hostid:通讯机编号0-239
//4. terid: 终端设备编号0-239
//5. areaid:防区编号1-8
//6. commandcode:返回的命令码,就是上面74行定义的Alarm_Event
//7. *t_msg:设备通讯显示信息指针,调试用。如果为NULL,不返回任何信息
//报警信息
void ( *Es_Alarm_Information )( const void *sender,uchar receid,uchar hostid,uchar terid,int areaid,Alarm_Event eventid,char *t_msg ); //其中Alarm_Event是枚举类型
}Es_callback_t;
转换成C#委托:
[DllImport("EsLib", EntryPoint = "Init_Eslib", CallingConvention = CallingConvention.StdCall)]
public static extern System.IntPtr Init_Eslib(IntPtr sender, ref Es_callback_t CallBack);
[UnmanagedFunctionPointer(CallingConvention.Cdecl,CharSet=CharSet.Auto)]
public delegate void Es_Alarm_Information(System.IntPtr sender, byte receid, byte hostid, byte terid, int areaid, Alarm_Event eventid,string t_msg);
结构体:
public struct Es_callback_t
{
public Es_Alarm_Information Hak_Alarm_Information;
}
回调函数:
public static void Hak_Alarm_Information(System.IntPtr sender, byte receid, byte hostid, byte terid, int areaid, Alarm_Event eventid,string t_msg){};
调用:
Es_callback_t g_HakCallBack = new Es_callback_t();
g_HakCallBack.Hak_Alarm_Information = new Es_Alarm_Information(Hak_Alarm_Information);
flag = Init_Eslib(this.Handle, ref g_HakCallBack);
Start_Eslib(flag, 3999, 1000, 3);//启动udp3999端口
问题:初始化没有问题,问题是一有消息传回来,
dll就有错误:下面框架不正确或者缺失,[email protected]()等等,
请指点一下,多谢了!
------解决思路----------------------
推荐你一个工具:Pinvoke interop assistant,你去搜下,可以直接转换你想要的。
我是小尾巴
-------------------------------------------
.net高级技术讨论群(379121324)
------解决思路----------------------
C 中Init_Eslib怎么定义的
------解决思路----------------------
看样子,这是某个设备的接口API。
是不是你的dll有问题,在C++里,Start_Eslib和Init_Eslib具体是怎么实现的(不只是声明),在实现里,有没有调用windows标准API函数,检查源代码后,用C++重新生成dll
还有,在[dllimport……里面,没有声明Start_Eslib的
“转换成C#委托:”,这句不解,你是调用C++生成的dll吗?
一般设备备有多种语言的接口,难道这个没有C#版本的接口API
------解决思路----------------------

可以结贴了。