求助!在C#里调用VC中DLL问题
VC动态库名WhUdpTools.dll
以下是VC中做的一个事例,我想用C#调用WhUdpTools.dll写一个和下面一样例子,求助帮助!
#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "WhUdpTools.h"
char BufAddr1[1024], OtherEndAddr1[32];
double LocalUpdateTime1;
char BufAddr2[1024], OtherEndAddr2[32];
double LocalUpdateTime2;
void CallBackFun1(void * pBuf, long DataSize, unsigned short PID, char * pOtherEndAddr, double LocalUpdateTime)
{
printf("callback 1: pBuf[0]=0x%02x DataSize=%d LocalUpdateTime=%f LocalUpdateTime1=%f OtherEndAddr1=%s BufAddr1[0]=0x%02x PID=%d pOtherEndAddr=%s\n", * (char *)pBuf, DataSize, LocalUpdateTime, LocalUpdateTime1, OtherEndAddr1, BufAddr1[0], PID, pOtherEndAddr);
}
void CallBackFun2(void * pBuf, long DataSize, unsigned short PID, char * pOtherEndAddr, double LocalUpdateTime)
{
printf("callback 2: pBuf[0]=0x%02x DataSize=%d LocalUpdateTime=%f LocalUpdateTime2=%f OtherEndAddr2=%s BufAddr2[0]=0x%02x PID=%d pOtherEndAddr=%s\n", * (char *)pBuf, DataSize, LocalUpdateTime, LocalUpdateTime2, OtherEndAddr2, BufAddr2[0], PID, pOtherEndAddr);
}
int main(int argc, char* argv[])
{
WhUdpRecv * pWhUdpRecv = NULL;
WhUdpSend * pWhUdpSend1 = NULL;
WhUdpSend * pWhUdpSend2 = NULL;
{
pWhUdpRecv = new WhUdpRecv("", 6000, 4, CallBackFun1);
//pWhUdpRecv->WhSetRecv(0, BufAddr1, sizeof(BufAddr1), OtherEndAddr1, &LocalUpdateTime1, NULL, 0);
printf("1 pWhUdpRecv=%d isOK=%d\n", pWhUdpRecv, pWhUdpRecv->isOK);
}
{
pWhUdpSend1 = new WhUdpSend(4);
char BufAddr1[1024] = {1, 2, 3, 4};
double LocalUpdateTime1 = 0;
pWhUdpSend1->WhSetSend(0, BufAddr1, 32, "127.0.0.1", 6000, NULL);
printf("3 pWhUdpSend1=%d isOK=%d\n", pWhUdpSend1, pWhUdpSend1->isOK);
pWhUdpSend2 = new WhUdpSend(4);
char BufAddr2[1024] = {5, 6, 7, 8};
double LocalUpdateTime2 = 0;
pWhUdpSend2->WhSetSend(1, BufAddr2, 32, "127.0.0.1", 6001, &LocalUpdateTime2);
printf("4 pWhUdpSend2=%d isOK=%d\n", pWhUdpSend2, pWhUdpSend2->isOK);
while(! _kbhit())
{
pWhUdpSend1->WhSend(0);
printf("LocalUpdateTime1=%f\n", LocalUpdateTime1);
pWhUdpSend2->WhSend(1);
printf("LocalUpdateTime2=%f\n", LocalUpdateTime2);
Sleep(10);
}
printf("exit 1\n");
delete pWhUdpRecv;
printf("exit 2\n");
delete pWhUdpSend1;
printf("exit 3\n");
delete pWhUdpSend2;
printf("exit 4\n");
}
getch();
printf("exit 5\n");
return 0;
}
------解决方案--------------------DllImport 和 extern关键字结合使用
------解决方案--------------------
------解决方案--------------------不过你这个里面只有最后一个需要加吧,其他的都是系统的不需要另外添加。
------解决方案--------------------
------解决方案--------------------参考
http://blog.csdn.net/jason_dct/article/details/7493755
------解决方案--------------------
楼主这个也就是一个udp通信的东西。没有必要非要用他的这个吧。c# udp通信相当简单可以直接用的。
1,2,7楼纯胡扯。
楼主要