当我在 Windows Vista 中编写有关 IO 完成端口的程序时,第一个示例不起作用,GetQueuedCompletionStatus() 无法获取任何 OVERLAPPED 结构。
所以我把 OVERLAPPED 结构放在全局范围内,它的效果非常好。这是为什么?
代码1:
int main()
{
OVERLAPPED o;
..
CreateIoCompletionPort(....);
for (int i = 0; i<10; i++)
{
WriteFile(..,&o);
OVERLAPPED* po;
GetQueuedCompletionStatus(..,&po);
}
}
代码2:
OVERLAPPED o;
int main()
{
..
CreateIoCompletionPort(....);
for (int i = 0; i<10; i++)
{
WriteFile(..,&o);
OVERLAPPED* po;
GetQueuedCompletionStatus(..,&po);
}
}