Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateFile failed in Window Mobile 6.0

7 views
Skip to first unread message

turbosun

unread,
Jul 12, 2009, 3:31:13 AM7/12/09
to
Hi there,
I want to use CreateFile() function to read files, but I failed many
times.Here is my code
m_hFile = CreateFile( szFileName, FILE_READ_DATA, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL );
the szFileName is "cube.x",the *.x file is copied and located nearly
everywhere.But the m_hFile is still INVALID_HANDLE_VALUE

I am waiting for your response eagarly.thank you very much!

Bruce Eitman [eMVP]

unread,
Jul 11, 2009, 10:00:11 PM7/11/09
to
And the result of GetLastError() is?
And the data type for szFileName is?

Come on help us help you a little bit.

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

EuroTech Inc.
www.EuroTech.com

"turbosun" <sunhh...@126.com> wrote in message
news:O4r4DSkA...@TK2MSFTNGP05.phx.gbl...

turbosun

unread,
Jul 12, 2009, 10:15:19 PM7/12/09
to
Hi.
the return of GetLastError() is 2,
the data type for szFileName is LPCTSTR
Thank you !

"Bruce Eitman [eMVP]" <bruce.eit...@EuroTech.com.nospam> wrote in
message news:uL2gBSpA...@TK2MSFTNGP04.phx.gbl...

turbosun

unread,
Jul 12, 2009, 11:55:35 PM7/12/09
to
By the way i am using device emulator. I can create new files (szFilename =
L"test.x"),but i don't know where they are.I have searched all my computer.

Bruce Eitman [eMVP]

unread,
Jul 12, 2009, 9:46:40 AM7/12/09
to
The are in RAM in the "\" folder of the emulator. What you should do is
specify the path to your file, then you will know where it is. Windows CE
doesn't have a current directory, so no path means the root folder.

Did you look up what last error of 2 means? See
http://geekswithblogs.net/BruceEitman/archive/2008/07/14/platform-builder-interpreting-getlasterror.aspx,
but I did the work for you and it means file not found. File not found can
mean a few things, like that you didn't specify the path to the file, the
file doesn't exist, or that you are using non-unicode string copy functions.

One test to see if you are handling the file name correctly is to display
the name in a message box, if it looks okay there it should be okay, and the
problem is that the file doesn't exist where you are trying to open it.

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

EuroTech Inc.
www.EuroTech.com

"turbosun" <sunhh...@126.com> wrote in message

news:uNCJQ%23uAKH...@TK2MSFTNGP02.phx.gbl...

turbosun

unread,
Jul 13, 2009, 1:40:49 AM7/13/09
to
In fact i want to read a file, i specify the path such as
L"d://project//cube.x".but the GetLastError() returns 3. so i add the cube.x
file to the project. szFilename is L"cube.x", emulator can get the handle of
the file,but i cannot read file using ReadFile() . GetLastError() returns 5.
Thank you very much! I learn so much from you.

Bruce Eitman [eMVP]

unread,
Jul 12, 2009, 2:00:05 PM7/12/09
to
Okay, now you have lost me. Windows Mobile doesn't have drive letters at
all, so of course you can't open a file at D: anything. Then consider using
"\\" instead of "//".

I will leave it to you to figure out what error codes 3 and 5 mean.

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

EuroTech Inc.
www.EuroTech.com

"turbosun" <sunhh...@126.com> wrote in message

news:OuH%23D5vAK...@TK2MSFTNGP02.phx.gbl...

ET

unread,
Jul 30, 2009, 6:25:56 PM7/30/09
to
It seems to me that you want to open a file that is not in your emulator
file system, but rather on your PC's.
In order to have your program, which is running in the emulator, access a
file that is not in your emulator file system, but somewhere on the D: drive
of your PC, you must make this D: drive available as an emulated "Storage
Card" to the emulator (under the File menu-item).
After you have done this you can open the file using a path such as the
following:
L"\\Storage Card\\project\\cube.x"
(assuming you mapped D:\ to the storage card).

Hope this helps,

Etienne

"turbosun" <sunhh...@126.com> schreef in bericht
news:OuH%23D5vAK...@TK2MSFTNGP02.phx.gbl...

0 new messages