ROUTINE与功能不兼容

ROUTINE与功能不兼容

本文介绍了LPOVERLAPPED_COMPLETION_ROUTINE与功能不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 winapi 中的 WriteFileEx 将数据异步写入文件,但是我对回调有疑问。

I want to asynchronously write data to file using WriteFileEx from winapi, but I have a problem with callback.

我正在跟踪错误:
类型为 void(*)(DWORD dwErrorCode,DWORD dwNumberOfBytesTransfered,LPOVERLAPPED lpOverlapped)的参数不兼容参数类型为 LPOVERLAPPED_COMPLETION_ROUTINE

I'm getting follow error: an argument of type "void (*) (DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped)" is incompatible with parameter of type "LPOVERLAPPED_COMPLETION_ROUTINE"

我在做什么错了?

这是代码:

// Callback
void onWriteComplete(
        DWORD dwErrorCode,
        DWORD dwNumberOfBytesTransfered,
        LPOVERLAPPED lpOverlapped) {
    return;
}

BOOL writeToOutputFile(String ^outFileName, List<String ^> ^fileNames) {
    HANDLE hFile;
    char DataBuffer[] = "This is some test data to write to the file.";
    DWORD dwBytesToWrite = (DWORD) strlen(DataBuffer);
    DWORD dwBytesWritten = 0;
    BOOL bErrorFlag = FALSE;

    pin_ptr<const wchar_t> wFileName = PtrToStringChars(outFileName);

    hFile = CreateFile(
        wFileName,              // name of the write
        GENERIC_WRITE,          // open for writing
        0,                      // do not share
        NULL,                   // default security
        CREATE_NEW,             // create new file only
        FILE_FLAG_OVERLAPPED,
        NULL);                  // no attr. template

    if (hFile == INVALID_HANDLE_VALUE) {
        return FALSE;
    }

    OVERLAPPED oOverlap;
    bErrorFlag = WriteFileEx(
        hFile,           // open file handle
        DataBuffer,      // start of data to write
        dwBytesToWrite,  // number of bytes to write
        &oOverlap,      // overlapped structure
        onWriteComplete),

    CloseHandle(hFile);
}


推荐答案

您应该先阅读仔细。这部分尤其重要:

You should start by reading the documentation carefully. This part is of particular import:

您不满足该要求,并且您需要紧急解决该问题。

You are not meeting that requirement, and you need to tackle that issue urgently.

对于编译器错误,这很简单。您的回调不符合要求。再次查阅,其签名为:

As for the compiler error, that's simple enough. Your callback does not meet the requirements. Again consult the documentation where its signature is given as:

VOID CALLBACK FileIOCompletionRoutine(
  _In_     DWORD dwErrorCode,
  _In_     DWORD dwNumberOfBytesTransfered,
  _Inout_  LPOVERLAPPED lpOverlapped
);

您已省略 CALLBACK 约定。

这篇关于LPOVERLAPPED_COMPLETION_ROUTINE与功能不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:13