使用完全端口接受数据后,主线程中不能再使用任何内存,为什么? ( 积分: 50 )

  • 主题发起人 主题发起人 男生111
  • 开始时间 开始时间

男生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);
}
}
 
我使用完全端口接受数据后,向主线程发了一个消息,想把接受到的数据在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);
}
}
 
这个网站难道没有高手吗?张无鸡不是说自己精通完全端口吗?为什么不回答我?我在等你
 
自由界面和报表的完美解决方案!
http://www.anylib.com
 
我也遇到同样的问题,接收大数据量的时候,然后把这些数据入库就报内存出错,留下联系方式,一起讨论讨论!
 
我也有过错误, 使用完全端口做服务器接受和发送数据时, 服务器只要不获得焦点就工作正常, 一获得焦点就报‘重叠I/O操作正在进行中’
 
多人接受答案了。
 
后退
顶部