男
男生111
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用完全端口接受数据后,向主线程发了一个消息,想把接受到的数据在FORM中显示出来,但发现在消息响应函数中不能给任何变量赋值,(接受数据前我在一BUTTON中发送消息没问题,但当用GetQueuedCompletionStatus接受数据后再发送消息,就报内存错误,甚至我给一个整形赋值也报错,为什么)
请哪位大侠给解释一下,我刚接触完全端口,谢谢
完全端口GetQueuedCompletionStatus接受数据线程如下
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID)
{
HANDLE CompletionPort = (HANDLE) CompletionPortID;
DWORD BytesTransferred;
LPOVERLAPPED Overlapped;
LPPER_HANDLE_DATA PerHandleData;
LPPER_IO_DATA PerIoData;
DWORD SendBytes, RecvBytes;
DWORD Flags;
BOOL ret;
int i;
AnsiString lizhe;
while(TRUE)
{
ret = GetQueuedCompletionStatus(CompletionPort,
&BytesTransferred,(LPDWORD)&PerHandleData,
(LPOVERLAPPED *) &PerIoData, INFINITE);
if ((BytesTransferred == 0) &&(PerIoData->OperationType == RECV_POSTED||
PerIoData->OperationType == SEND_POSTED))
{
closesocket(PerHandleData->Socket);
GlobalFree(PerHandleData);
GlobalFree(PerIoData);
continue;
}
if (PerIoData->OperationType == RECV_POSTED)
{
short lll;
memcpy(m_szBuffer,PerIoData->DataBuf.buf,BytesTransferred);
PostMessage(Form1->Handle, WM_MYWANQUANPORT, BytesTransferred, 0);
}
else{
PostMessage(Form1->Handle, WM_MYWANQUANPORT, 0, 2);
}
Flags = 0;
ZeroMemory(&(PerIoData->Overlapped),
sizeof(OVERLAPPED));
PerIoData->DataBuf.len = 4095;
PerIoData->DataBuf.buf = PerIoData->szBuffer;
PerIoData->OperationType = RECV_POSTED;
WSARecv(PerHandleData->Socket,
&(PerIoData->DataBuf), 1, &RecvBytes,
&Flags, &(PerIoData->Overlapped), NULL);
}
}
请哪位大侠给解释一下,我刚接触完全端口,谢谢
完全端口GetQueuedCompletionStatus接受数据线程如下
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID)
{
HANDLE CompletionPort = (HANDLE) CompletionPortID;
DWORD BytesTransferred;
LPOVERLAPPED Overlapped;
LPPER_HANDLE_DATA PerHandleData;
LPPER_IO_DATA PerIoData;
DWORD SendBytes, RecvBytes;
DWORD Flags;
BOOL ret;
int i;
AnsiString lizhe;
while(TRUE)
{
ret = GetQueuedCompletionStatus(CompletionPort,
&BytesTransferred,(LPDWORD)&PerHandleData,
(LPOVERLAPPED *) &PerIoData, INFINITE);
if ((BytesTransferred == 0) &&(PerIoData->OperationType == RECV_POSTED||
PerIoData->OperationType == SEND_POSTED))
{
closesocket(PerHandleData->Socket);
GlobalFree(PerHandleData);
GlobalFree(PerIoData);
continue;
}
if (PerIoData->OperationType == RECV_POSTED)
{
short lll;
memcpy(m_szBuffer,PerIoData->DataBuf.buf,BytesTransferred);
PostMessage(Form1->Handle, WM_MYWANQUANPORT, BytesTransferred, 0);
}
else{
PostMessage(Form1->Handle, WM_MYWANQUANPORT, 0, 2);
}
Flags = 0;
ZeroMemory(&(PerIoData->Overlapped),
sizeof(OVERLAPPED));
PerIoData->DataBuf.len = 4095;
PerIoData->DataBuf.buf = PerIoData->szBuffer;
PerIoData->OperationType = RECV_POSTED;
WSARecv(PerHandleData->Socket,
&(PerIoData->DataBuf), 1, &RecvBytes,
&Flags, &(PerIoData->Overlapped), NULL);
}
}