如何将IcmpSendEcho2与PIO_APC_ROUTINE一起使用? [英] How to use IcmpSendEcho2 with PIO_APC_ROUTINE?
问题描述
I'm a c++ newbie and I'm trying to make a "ping tool" with IcmpSendEcho2 but I can't make it to work with APCs.
我遇到了此编译错误:
>error C2220: warning treated as error - no 'object' file generated
>warning C4191: 'type cast' : unsafe conversion from 'PIO_APC_ROUTINE (__cdecl *)(PVOID,PIO_STATUS_BLOCK,ULONG)' to 'PIO_APC_ROUTINE'
> Calling this function through the result pointer may cause your program to fail
这是我的APC声明:
PIO_APC_ROUTINE GotIt(PVOID param, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved);
这是我的APC定义:
PIO_APC_ROUTINE GotIt(PVOID param, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved)
{
printf("GOT IT!\n");
return NULL;
}
这就是我制作IcmpSendEcho2的方法:
And this is how I make the IcmpSendEcho2:
DWORD dwRetVal = IcmpSendEcho2(hIcmpFile, NULL, (PIO_APC_ROUTINE) GotIt, NULL,
ipaddr, SendData, sizeof (SendData), NULL,
ReplyBuffer, ReplySize, 1000);
我以为'(PIO_APC_Rountine)GotIt'会做到的,因为我发现
I thought '(PIO_APC_Rountine) GotIt' would do it, because I found this, but apparently I'm missing something.
如果您需要任何其他信息,请告诉我.
If you need any additional information, let me know.
非常感谢.
推荐答案
首先,不要转换回调函数. 所有.
第二,PIO_APC_ROUTINE
声明为:
typedef
VOID
(NTAPI *PIO_APC_ROUTINE) (
IN PVOID ApcContext,
IN PIO_STATUS_BLOCK IoStatusBlock,
IN ULONG Reserved
);
因此您的GotIt
函数应为:
VOID NTAPI GotIt(
IN PVOID ApcContext,
IN PIO_STATUS_BLOCK IoStatusBlock,
IN ULONG Reserved
);
NTAPI
是__stdcall
,而不是默认的__cdecl
,这是错误消息告诉您的内容.
NTAPI
is __stdcall
, not the default __cdecl
, which is what the error message is telling you.
您对此做了什么:
PIO_APC_ROUTINE GotIt(PVOID param, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved);
...声明了一个返回函数指针的函数.这不是你想要的.
...is declare a function that returns a function pointer. This is not what you wanted.
这篇关于如何将IcmpSendEcho2与PIO_APC_ROUTINE一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!