代码如下:
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutineCpy;
LPWSABUF lpBuf;
LPDWORD lpRecvLen;
............................
void CALLBACK MyCompletionRoutine(
IN DWORD dwError,
IN DWORD cbTransferred,
IN LPWSAOVERLAPPED lpOverlapped,
IN DWORD dwFlags
)
{
WaitForSingleObject(hMutex02,INFINITE);
RtlZeroMemory(lpRMemory,4096);
CopyMemory(lpRMemory,lpBuf->buf,lpBuf->len);
*(DWORD*)((BYTE*)lpRMemory+4090) = *lpRecvLen;
MessageBox(NULL,"What the Hell!!!!!!",NULL,MB_OK);//句2
ReleaseMutex(hMutex02);
hWnd = FindWindow(NULL,"GetBuffer");
PostMessage(hWnd,(WM_USER+101),0,0);
lpCompletionRoutineCpy( dwError,cbTransferred,lpOverlapped,dwFlags );
}
int WSAAPI WSPRecv(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd,
LPDWORD lpFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
LPWSATHREADID lpThreadId,
LPINT lpErrno
)
{
if (MB_Flag)
{
if (lpCompletionRoutine&&lpOverlapped)
{
MessageBox(NULL,"What the Fuck!",NULL,MB_OK);//句1
lpBuf = lpBuffers;
lpRecvLen = lpNumberOfBytesRecvd;
lpCompletionRoutineCpy = lpCompletionRoutine;
lpCompletionRoutine = MyCompletionRoutine;
}
}
return NextProcTable.lpWSPRecv(s,lpBuffers,dwBufferCount,lpNumberOfBytesRecvd,lpFlags,
lpOverlapped,lpCompletionRoutine,lpThreadId,lpErrno);
}
句1执行了,这说明是重叠操作,我把原来的CompletionRoutine保存在全局变量lpCompletionRoutineCpy中,用MyCompletionRoutine替代原来的CompletionRoutine,可MyCompletionRoutine根本就没被调用,因为句2的MessageBox没有出现
这是为什么?
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课