gpt4 book ai didi

c++ - Exe 在 BackupRead Windows 函数中崩溃

转载 作者:行者123 更新时间:2023-11-28 05:35:00 26 4
gpt4 key购买 nike

下面是我尝试备份文件的 C++ 代码,包括安全信息。我使用了备份读取,但每当调用代码时,exe 就会崩溃。

char buff[225280];
DWORD numberOfBytesToRead = 225280;
DWORD dwBytesRead=0, dwBytesWritten, dwBytesRead2=0;
BOOL bProcessSecurity = TRUE;
LPWSTR sourceBackupFile = L"E:\\myFolder\\backup.txt";
HANDLE source = CreateFile(sourceBackupFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
// Check for errors
if (source == INVALID_HANDLE_VALUE) {
cout<<"The Handle is Invalid:"<<GetLastError()<<endl;
}
else
{
cout<< "\n The source file is in E:\\myFolder\\backup.txt" <<endl ;
}
LPDWORD numberofbytedsreadinreadFile = 0;

cout << "Point Of Crash" << endl;
if (!BackupRead(
source,
&buff,
numberOfBytesToRead,
numberofbytedsreadinreadFile,
FALSE,
TRUE,
NULL
))
{

cout << "Backup Read Failed with the error::" << GetLastError() << endl ;

}

它在崩溃前打印这个

The source file is in E:\\myFolder\\backup.txt
"Point of Crash"

最佳答案

您将 NULL 作为最后一个参数传递给 BackupRead,根据 docs 这显然是无效的.

lpContext [out] Pointer to a variable that receives a pointer to an internal data structure used by BackupRead to maintain context information during a backup operation. You must set the variable pointed to by lpContext to NULL before the first call to BackupRead for the specified file or directory. The function allocates memory for the data structure, and then sets the variable to point to that structure. You must not change lpContext or the variable that it points to between calls to BackupRead. To release the memory used by the data structure, call BackupRead with the bAbort parameter set to TRUE when the backup operation is complete.

您应该传递一个指向它的指针,该指针指向 null,而不是 null 值。 (LPVOIDvoid*LPVOID**表示void**)

numberofbytedsreadinreadFile 相同:您应该将参数传递给现有变量,而不是空指针,它是一个输出参数。

 void* backupContext = NULL;
int numberOfBytesRead = 0;
cout << "Point Of Crash" << endl;
if (!BackupRead(
source,
&buff,
numberOfBytesToRead,
&numberOfBytesRead,
FALSE,
TRUE,
&backupContext
))

如果您得到一个无效的句柄,您也应该从此方法返回而不是继续。

关于c++ - Exe 在 BackupRead Windows 函数中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38525647/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com