I would like to make a ping function using IcmpSendEcho2()
(it shows correct ping) but the problem is when I call this function, my application freezes for several milliseconds. I learned that I have to call the function asynchronously, but the Microsoft guide doesn't provide a tutorial about that.
I've been searching the Internet but I could not find a solution.
This is what I have so far:
unsigned long destAdress = inet_addr("164.132.205.2");
static PIO_APC_ROUTINE g_pfnIcmpCallback;
HANDLE hIcmpFile = IcmpCreateFile();
char SendData[32] = "Data Buffer";
LPVOID ReplyBuffer = NULL;
DWORD dwRetVal = 0;
DWORD ReplySize = 0;
ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
ReplyBuffer = (VOID*)malloc(ReplySize);
dwRetVal = IcmpSendEcho2(hIcmpFile, NULL, g_pfnIcmpCallback, NULL, destAdress, SendData, sizeof(SendData), NULL, ReplyBuffer, ReplySize, 5000);
int pintTime;
if (dwRetVal != 0) {
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
pintTime = pEchoReply->RoundTripTime;
g_logger.info(stdext::format("dwRetVal ", pintTime));
}
else {
g_logger.info(stdext::format("dwRetVal = 0"));
return 0;
}
return pintTime;
The error I get in VS 2013:
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include\icmpapi.h(258): error C2061: syntax error : identifier 'PIO_APC_ROUTINE' (..\src\client\game.cpp)
Did I do something wrong?