szFileName contains calc.exe
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
dwFileSize = GetFileSize(hFile, NULL);
error code which i am getting is 183....which says "Cannot create a file when that file already exists"GetFIleSize function is failing....
can i use CreateFile with first argument as cal.exe....??
If you don't want to create a new file, maybe try OPEN_EXISTING instead of OPEN_ALWAYS.
OPEN_ALWAYS makes a new file if the file does not exist. OPEN_EXISTING fails, if the file does not exist. I am not sure it helps, but try it out.
Ohh, I see you beat me to it...
Why wouldn't it?
If it doesn't, then his system has big problems.
OPEN_EXISTING -> opens a file if it exists ...
otherwise CreateFile will fail ..
OPEN_ALWAYS -> opens a file if it exists
otherwise new file will be created...
i tried OPEN_EXISTING also ....but again GetFileSize returns 0.
calc.exe exists ......
could you please post your declaration of the path to calc.exe?
also try checking the value of hFile against INVALID_HANDLE_VALUE. if the call to CreateFile is failing, then that is your problem, and it could be failing due to an incorrect path to calc.exe, because otherwise everything looks ok as long as you are using OPEN_EXISTING (and are not using OPEN_ALWAYS together with it).
path to calc.exe was incorrect