Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ GetFileSizeEx会损坏文件句柄_C++_C++builder 2010_C++builder 6 - Fatal编程技术网

C++ GetFileSizeEx会损坏文件句柄

C++ GetFileSizeEx会损坏文件句柄,c++,c++builder-2010,c++builder-6,C++,C++builder 2010,C++builder 6,目前,我正在使用GetFileSizeEx在写入日志文件之前跟踪日志文件的大小。我们的空间有限,如果我们试图创建一个大于100兆字节的文件,我们就会停止记录数据。问题是由于某些原因,GetFileSizeEx将损坏我正在使用的文件句柄 if( hFileHandle != INVALID_HANDLE_VALUE && hFileHandle != NULL ) { asDbgMsg = asDbgMsg + asDelimeter; dwBytesToWrite =asDb

目前,我正在使用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 );
 }
}
if(hFileHandle!=无效的\u HANDLE\u值&&hFileHandle!=NULL)
{
asDbgMsg=asDbgMsg+asDelimeter;
dwBytesToWrite=asDbgMsg.Length();
pWrtBuffer=asDbgMsg.c_str();
//获取要写入的文件大小。
PLARGE_整数lpFileSize;
GetFileSizeEx(hFileHandle,lpFileSize);
//如果文件超过100 mb,请不要将其写出!
如果(lpFileSize->QuadPart<104857600)
{
WriteFile(hFileHandle、pWrtBuffer、dwBytesToWrite和dwbytesswrite,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 );
 }
}
if(hFileHandle!=无效的\u HANDLE\u值&&hFileHandle!=NULL)
{
asDbgMsg=asDbgMsg+asDelimeter;
dwBytesToWrite=asDbgMsg.Length();
pWrtBuffer=asDbgMsg.c_str();
//获取我们将要编写的文件大小。
德沃德检验;
GetFileSize(hFileHandle和test);
//如果文件超过100 mb,请不要将其写出!
如果(试验<104857600)
{
WriteFile(hFileHandle、pWrtBuffer、dwBytesToWrite和dwbytesswrite,NULL);
}
}
但是,我不想使用非扩展函数。我已经删除了该文件,以确保没有其他进程对其进行锁定,但它在创建该文件时仍然存在问题。我应该注意的是,这个错误在Builder6下不会发生,只有Rad Studio 2010


谢谢您的帮助。

尝试使用大整数而不是大整数。通常情况下,PLARGE_INTEGER是一个指针,而不是一个值。

感谢builder 6的“帮助”,并认为它是一个正常值。