0
當前我正在使用GetFileSizeEx來跟蹤在寫入日誌文件之前有多大的日誌文件。如果我們嘗試創建一個大於100兆字節的文件,我們將停止記錄數據,但空間有限。問題出於某種原因,GetFileSizeEx將破壞我正在使用的文件句柄。GetFileSizeEx損壞文件句柄
if(hFileHandle != INVALID_HANDLE_VALUE && hFileHandle != NULL)
{
asDbgMsg = asDbgMsg + asDelimeter;
dwBytesToWrite =asDbgMsg.Length();
pWrtBuffer = asDbgMsg.c_str();
// Get the file size we are about to write to.
PLARGE_INTEGER lpFileSize;
GetFileSizeEx(hFileHandle, lpFileSize);
// Don't write out the file if it is more than 100 mb!
if(lpFileSize->QuadPart < 104857600)
{
WriteFile(hFileHandle, pWrtBuffer, dwBytesToWrite, &dwBytesWritten, NULL);
}
}
hFileHandle將從正常值(00000EB8)變爲在Rad studio的調試器中。
現在我已經使用GetFileSize功能,而不是解決了這個:
if(hFileHandle != INVALID_HANDLE_VALUE && hFileHandle != NULL)
{
asDbgMsg = asDbgMsg + asDelimeter;
dwBytesToWrite =asDbgMsg.Length();
pWrtBuffer = asDbgMsg.c_str();
// Get the file size we are about to write too.
DWORD test;
GetFileSize(hFileHandle, &test);
// Don't write out the file if it is more than 100 mb!
if(test < 104857600)
{
WriteFile(hFileHandle, pWrtBuffer, dwBytesToWrite, &dwBytesWritten, NULL);
}
}
然而,我寧可不使用非擴展功能。我刪除了該文件以確保其他進程沒有鎖定,但是在創建文件時仍然存在問題。我應該注意,這個錯誤不會發生在構建器6下,只有Rad Studio 2010.
謝謝你的幫助。
非常感謝製造商6「有幫助」,並認爲它是一個正常值。 – Alikar 2010-09-29 15:34:48