开发者

In WinCE, CreateFile function: File open failed

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 usi开发者_开发问答ng WinCE. Now the question changes to, How to copy files in Computer to Emulator ?


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".


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().


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜