本文介绍了为什么回调给ReadFileEx()没有接受正确的OVERLAPPED结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,我的回调没有接收到正确的的地址OVERLAPPED 在通话结束后结构 ReadFileEx 。这是什么原因?

更新 - 例如:

 的#include<&stdio.h中GT;
#包括LT&;&WINDOWS.H GT;无效__stdcall completion_routine(
    无符号长dwError code,
    无符号长dwNumberOfBytesTransfered,
    OVERLAPPED * lpOverlapped的)
{
    的printf(重叠=%P \\ N,lpOverlapped的);
}INT _tmain(INT ARGC,ARGV LPTSTR [])
{
    HANDLE hvolume =的CreateFile(
        _T(C:\\\\ \\\\的Windows Notepad.exe的),FILE_READ_DATA,
        FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
        空,OPEN_EXISTING,0,NULL);
    烧焦tempbuf [512];
    OVERLAPPED tempoverlapped = {};
    的printf(%P \\ N,&安培; tempoverlapped);
    如果(ReadFileEx(hvolume,tempbuf,sizeof的(tempbuf)
                   &安培; tempoverlapped,&安培; completion_routine)
        &功放;&安培; GetLastError函数()== ERROR_SUCCESS)
    {
        SleepEx(INFINITE,TRUE);
    }
}


解决方案

我忘了指定 FILE_FLAG_OVERLAPPED 的CreateFile

For some reason, my callback isn't receiving the address of the correct OVERLAPPED structure after a call to ReadFileEx. What can cause this?

Update -- example:

#include <stdio.h>
#include <Windows.h>

void __stdcall completion_routine(
    unsigned long dwErrorCode,
    unsigned long dwNumberOfBytesTransfered,
    OVERLAPPED *lpOverlapped)
{
    printf("Overlapped = %p\n", lpOverlapped);
}

int _tmain(int argc, LPTSTR argv[])
{
    HANDLE hvolume = CreateFile(
        _T("C:\\Windows\\Notepad.exe"), FILE_READ_DATA,
        FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
        NULL, OPEN_EXISTING, 0, NULL);
    char tempbuf[512];
    OVERLAPPED tempoverlapped = { };
    printf("%p\n", &tempoverlapped);
    if (ReadFileEx(hvolume, tempbuf, sizeof(tempbuf),
                   &tempoverlapped, &completion_routine)
        && GetLastError() == ERROR_SUCCESS)
    {
        SleepEx(INFINITE, TRUE);
    }
}
解决方案

I forgot to specify FILE_FLAG_OVERLAPPED to CreateFile.

这篇关于为什么回调给ReadFileEx()没有接受正确的OVERLAPPED结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 14:12