WaitForSingleObject提供无效句柄

时间:2011-04-11 08:16:34

标签: c++ asynchronous waitforsingleobject

h=CreateFile("c:\\test.txt",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_READONLY|FILE_FLAG_OVERLAPPED,NULL);

    OVERLAPPED ol2;
    memset(&ol2,0,sizeof(OVERLAPPED));
    ol2.hEvent=CreateEvent(NULL,false,false,NULL);
    if(!ReadFile(h,iobuffer+pointsize,value,NULL,&ol2))
    printf("Last Error %u",GetLastError());
    if(WaitForSingleObject(&ol2.hEvent,INFINITE)!=0){
        printf("Last Error %u \n",GetLastError());

    }

WaitForsingleobject返回无效句柄,但我不明白为什么......

1 个答案:

答案 0 :(得分:4)

我认为应该写:

if(WaitForSingleObject(ol2.hEvent,INFINITE)!=0){
            printf("Last Error %u \n",GetLastError());

请注意已移除的&在ol2.hEvent之前