tags:

views:

59

answers:

3

Hi, I need to do file operations in WinCE in a Windows mobile 6 project in visual studio 2008.

For opening a file i did like below.

    HANDLE  hFile = CreateFile(__TEXT("\\1.txt"), GENERIC_READ ,
             FILE_SHARE_READ, NULL, OPEN_EXISTING, 
             FILE_ATTRIBUTE_NORMAL, NULL);

But hFile is coming as 0xffffffff. File open failed. File exists in d:\

I tried paths like d:\\1.txt , 1.txt But none of them are working.

Filename path should be relative to which directory ?

Kindly help me.

EDIT: The problem is it is trying to search the path in WinCE emulator. But my file is present in System harddisk d:\ So i am unable to access files present in my computer when using WinCE. Now the question changes to, How to copy files in Computer to Emulator ?

+1  A: 

Trying to guess at the problem isn't useful. Ask Windows what was wrong, use GetLastError(). Lookup the error code in WinUser.h or use FormatMessage().

Hans Passant
A: 

Wny you are not using Boost Filesystem library?

It is very simple and good for all kind of works with files and directories.

http://www.boost.org/doc/libs/1_44_0/libs/filesystem/v2/doc/index.htm

Davit Siradeghyan
+1  A: 

My guess is that your file is not there.

In order to share a folder from your harddisk with the emulator, go to your emulator menu: "File -> Configure ... -> General -> Shared folder:". This folder will be seen as "Storage Card".

Lets say you map d:\wm, then you put 1.txt in d:\wm, afterwards the file path for ::CreateFile becomes: L"\\storage card\\1.txt".

Cristian Adam