可以异步调用IcmpSendEcho2吗?

时间:2018-07-11 15:06:42

标签: c++ winapi

我想使用IcmpSendEcho2()创建ping函数(它显示正确的ping),但是问题是当我调用此函数时,我的应用程序冻结了几毫秒。我了解到必须异步调用该函数,但是Microsoft指南没有提供有关该函数的教程。

我一直在搜索Internet,但是找不到解决方案。

这是我到目前为止所拥有的:

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;

我在VS 2013中遇到的错误:

  

1> C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.1A \ include \ icmpapi.h(258):错误C2061:语法错误:标识符'PIO_APC_ROUTINE'(.. \ src \ client \ game.cpp)

我做错了吗?

0 个答案:

没有答案