我希望異步數據寫入使用WriteFileEx從WINAPI到文件不兼容,但我有回調的一個問題。LPOVERLAPPED_COMPLETION_ROUTINE與功能
我得到如下錯誤: 類型的參數 「無效(*)(DWORD dwErrorCode,DWORD dwNumberOfBytesTransfered,LPOVERLAPPED lpOverlapped的)」 與類型 「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);
}
謝謝!現在,它的工作 –
順便說一句,你能再次幫助我嗎?回調在這裏根本不叫。我在等,但沒有任何事發生 –
您需要閱讀文檔。你沒有檢查返回值。或者調用GetLastError。 –