I want to use CreateFile() function in Visual C++. when I am using it in this way:-
{
BOOL bTest=FALSE;
DWORD dwNumRead=0;
HANDLE hFile=CreateFile(L"D:\\a.dat",GENERIC_READ,FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
bTest= CloseHandle(hFile);
}
The value of bTest is coming out to be False and the file is not created.
Please, if possible, illustrate an example to create a file using CreateFile and tell me what I am doing wrong.
“OPEN_EXISTING : Opens a file or device, only if it exists. If the specified file or device does not exist, the function fails”. That’s your problem, I bet.
GetLastError()would tell you more, though.