下面是我的C++代碼,我嘗試備份一個文件,包括安全信息。我使用備份讀取,但每當代碼被稱爲EXE崩潰。Exec崩潰在BackupRead Windows功能
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"
崩潰之前它打印什麼?無效的句柄或有效的源文件?你不應該試圖用無效的句柄做任何事情。 – Dutow
它在沒有其他任何事情發生之前打印「碰撞點」。我只是試圖打開手柄,我沒有用它做任何事情。那之後我關閉了手柄。我想它不是一個問題,因爲它在此之前破解 – mano
該句柄用作BackupRead的參數。根據您的源代碼,您的程序應該在崩潰之前打印一個cout。 – Dutow