Reputation: 11
A very basic question, I cannot understand why I get error 2 with the simplest example of windows system programming book. I post the source:
#include <Windows.h>
#include <stdio.h>
#define BUF_SIZE 65536
int main(int argc, LPTSTR argv[]){
HANDLE fileIN, fileOUT;
DWORD nIn, nOut; //numero di byte LETTI/SCRITTI
CHAR buffer[BUF_SIZE];
if(argc!=3){
printf("Usage: %s file1 file2\n", argv[0]);
return 1;
}
//printf("%s\n",argv[0]);
//printf("%s\n",argv[1]);
//printf("%s\n",argv[2]);
fileIN = CreateFileW(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(fileIN == INVALID_HANDLE_VALUE){
printf("Invalid handle value, error %x\n", GetLastError());
return 2;
}
fileOUT = CreateFileW(argv[2], GENERIC_WRITE,0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL);
if(fileOUT == INVALID_HANDLE_VALUE){
printf("Invalid handle value, error %x\n", GetLastError());
return 3;
}
while(ReadFile(fileIN, buffer, BUF_SIZE, &nIn, NULL) && nIn > 0){
WriteFile(fileOUT, buffer, nIn, &nOut, NULL);
if(nIn != nOut){
printf("During copy, error %x\n", GetLastError());
return 4;
}
}
CloseHandle(fileIN);
CloseHandle(fileOUT);
return 0;
}
Can you help me please? I'm using MS VSc++ 2010 SP 1 Thank you all in advange N.
Upvotes: 1
Views: 3979
Reputation: 328
Please, forgive me if I am wrong but I believe that you are trying to create files with functions unicode and, may be, you are providing paths ansi. It is easy to test if I am wrong changing the terminating W into A. Please, forgive my possible error.
Upvotes: 0