0

現在、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でのみ発生することに注意してください。

お手伝いありがとう。

4

1 に答える 1

2

PLARGE_INTEGER の代わりに LARGE_INTEGER を使用してみてください。通常、PLARGE_INTEGER は値ではなくポインタです。

于 2010-09-29T15:19:08.713 に答える