Taurus
asked on
CreateFile fails in VS2005
If I create a test MFC dialog app. in VS2005 and in the OnInitDialog() generated code I add the following code just before the return:
DWORD d;
HANDLE h;
SetLastError(0);
h = CreateFile((LPCTSTR)"C:\\d ocument.rt f",FILE_RE AD_EA,FILE _SHARE_REA D,NULL,OPE N_EXISTING ,NULL,NULL );
d = GetLastError();
CreateFile fails with d=2. If I create a the same app. in VC++6 it works fine. What gives?
DWORD d;
HANDLE h;
SetLastError(0);
h = CreateFile((LPCTSTR)"C:\\d
d = GetLastError();
CreateFile fails with d=2. If I create a the same app. in VC++6 it works fine. What gives?
if you want to create new if the file does not exist use
OPEN_ALWAYS
CreateFile(path, // drive to open
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // default security attributes
OPEN_ALWAYS, // disposition
0, // file attributes
NULL); // don't copy any file's attributes
regards
Manish Regmi
OPEN_ALWAYS
CreateFile(path, // drive to open
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
NULL, // default security attributes
OPEN_ALWAYS, // disposition
0, // file attributes
NULL); // don't copy any file's attributes
regards
Manish Regmi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had forgotten about _T, and you are absolutely correct about using typecasting without reason. Thanks.
It means the file does not exist.
Also you don't need a type cast.
regards
Manish Regmi