現在、GetFileSizeExを使用して、ログファイルに書き込む前にログファイルのサイズを追跡しています。スペースには限りがあり、100メガバイトを超えるファイルを作成しようとすると、データのログ記録が停止します。問題は、何らかの理由で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)から????になります Radstudioのデバッガーで。
代わりに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では発生せず、RadStudio2010でのみ発生することに注意してください。
お手伝いありがとう。