Re: CreateFile fails

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



1. Use GetModuleFileName() function to know full path of your
executable.
2. Use wcsrchr() to strip out extra parts with '\' as delimiter.
3. Append \\Files\\%s.bak to the result of step 2. Now you should have
absolute path of your file.

BTW, I hope your code snippet is not with that sequence, right? There
must be something between line 2 and line 3.

(AT)
http://www.askarya.com

On Dec 25, 9:32 pm, Steve <St...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I have MFC based project, which run on HP iPAQ PDA under Windows Mobile 5.

I am trying to open file via parent directory as follows:

wchar_t fileName[128];
::memset(fileName, 0, sizeof(fileName ) ) ;
::wsprintf(fileName, L"..\\Files\\%s.bak", path ) ;
HANDLE file = ::CreateFile(fileName, GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0 ) ;

The file I am trying to open exists in the path specified.
However CreateFile function fails with error: "The system cannot find the
file specified." Can anyone suggest what is wrong?

Thanks

Thanks

.



Relevant Pages