---------- C++ -----------------
HHNET_API HHERR_CODE WINAPI HHNET_SearchAllServer(UINT nTimeWait,
void(WINAPI *CallbackServerFind)(DVS_MACHINE_TYPE nDeviceType,char *pDeviceName,
char *pIP,BYTE macAddr[6],WORD wPortWeb,WORD wPortListen,char *pSubMask,
char *pGateway,char *pMultiAddr,char *pDnsAddr,WORD wMultiPort,int nChannelNum,int nFindCount,DWORD dwDeviceID));------------- C# ------------------
[DllImport("HHNetClient.dll")]
private static extern int HHNET_SearchAllServer(UInt32 nTimeWait,CallbackServerFind fCallbackServerFind);public delegate void CallbackServerFind(DVS_MACHINE_TYPE nDeviceType, string pDeviceName, string pIP, byte[] macAddr, ushort wPortWeb, ushort wPortListen, string pSubMask, string pGateway, string pMultiAddr, string pDnsAddr, ushort wMultiPort, int nChannelNum, int nFindCount);
public static CallbackServerFind fCallbackServerFind;public long GetDeviceInfo()
{
fCallbackServerFind = new CallbackServerFind(m_vodCallbackServerFind);
res = HHNET_SearchAllServer(2345, fCallbackServerFind);
Thread.Sleep(1000);
}public void m_vodCallbackServerFind(DVS_MACHINE_TYPE nDeviceType, string pDeviceName, string pIP, byte[] macAddr , ushort wPortWeb, ushort wPortListen, string pSubMask, string pGateway, string pMultiAddr, string pDnsAddr, ushort wMultiPort, int nChannelNum, int nFindCount)
{
dName[Num] = pDeviceName;
Num = Num + 1;
return;
}
HHNET_SearchAllServer会多次调用Callback且Callback能调用,可是调用到最后一次时报“..程序错误..关闭”
HHNET_API HHERR_CODE WINAPI HHNET_SearchAllServer(UINT nTimeWait,
void(WINAPI *CallbackServerFind)(DVS_MACHINE_TYPE nDeviceType,char *pDeviceName,
char *pIP,BYTE macAddr[6],WORD wPortWeb,WORD wPortListen,char *pSubMask,
char *pGateway,char *pMultiAddr,char *pDnsAddr,WORD wMultiPort,int nChannelNum,int nFindCount,DWORD dwDeviceID));------------- C# ------------------
[DllImport("HHNetClient.dll")]
private static extern int HHNET_SearchAllServer(UInt32 nTimeWait,CallbackServerFind fCallbackServerFind);public delegate void CallbackServerFind(DVS_MACHINE_TYPE nDeviceType, string pDeviceName, string pIP, byte[] macAddr, ushort wPortWeb, ushort wPortListen, string pSubMask, string pGateway, string pMultiAddr, string pDnsAddr, ushort wMultiPort, int nChannelNum, int nFindCount);
public static CallbackServerFind fCallbackServerFind;public long GetDeviceInfo()
{
fCallbackServerFind = new CallbackServerFind(m_vodCallbackServerFind);
res = HHNET_SearchAllServer(2345, fCallbackServerFind);
Thread.Sleep(1000);
}public void m_vodCallbackServerFind(DVS_MACHINE_TYPE nDeviceType, string pDeviceName, string pIP, byte[] macAddr , ushort wPortWeb, ushort wPortListen, string pSubMask, string pGateway, string pMultiAddr, string pDnsAddr, ushort wMultiPort, int nChannelNum, int nFindCount)
{
dName[Num] = pDeviceName;
Num = Num + 1;
return;
}
HHNET_SearchAllServer会多次调用Callback且Callback能调用,可是调用到最后一次时报“..程序错误..关闭”
[DllImport("HHNetClient.dll"),CallingConvention.Cdecl]
加上[DllImport("HHNetClient.dll", CallingConvention = CallingConvention.Cdecl)]也一样~头大。。
原函数的回调函数里最后还有个参数 DWORD dwDeviceID,你 C# 定义的 delegate 少了那个参数
void(WINAPI *CallbackServerFind)(DVS_MACHINE_TYPE nDeviceType,char *pDeviceName,
char *pIP,BYTE macAddr[6],WORD wPortWeb,WORD wPortListen,char *pSubMask,
char *pGateway,char *pMultiAddr,char *pDnsAddr,WORD wMultiPort,int nChannelNum,int nFindCount,DWORD dwDeviceID));