我正在編寫一個用於備份某些指定文件的應用程序,因此使用備份API調用即CreateFile BackupRead和WriteFile API的。如何在C++中使用備份API進行備份
獲取錯誤訪問衝突讀取位置。
我附上下面的代碼。
#include <windows.h>
int main()
{
HANDLE hInput, hOutput;
//m_filename is a variable holding the file path to read from
hInput = CreateFile(L"C:\\Key.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
//strLocation contains the path of the file I want to create.
hOutput= CreateFile(L"C:\\tmp\\", GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, NULL, NULL);
DWORD dwBytesToRead = 1024 * 1024 * 10;
BYTE *buffer;
buffer = new BYTE[dwBytesToRead];
BOOL bReadSuccess = false,bWriteSuccess = false;
DWORD dwBytesRead,dwBytesWritten;
LPVOID lpContext;
//Now comes the important bit:
do
{
bReadSuccess = BackupRead(hInput, buffer, sizeof(BYTE) *dwBytesToRead, &dwBytesRead, false, true, &lpContext);
bWriteSuccess= WriteFile(hOutput, buffer, sizeof(BYTE) *dwBytesRead, &dwBytesWritten, NULL);
}while(dwBytesRead == dwBytesToRead);
return 0;
}
任何一個建議我如何使用這些API的?
謝謝。
我不從Vista瘦窗戶到Windows 8將允許您創建文件在C:目錄在程序 – billz
它是一個例子,目的地的位置可能是什麼... – user1603185