Re: Opening a file.
- From: "Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com>
- Date: Fri, 16 May 2008 10:19:07 -0500
The same might be said for the data buffer (inBuffer). Declaring a pointer
for it to put the data it reads into isn't quite the same as actually
allocating a buffer for it.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
"Bruce Eitman [eMVP]" <bruce.eitman.nospam@xxxxxxxxxxxxxxxxxxx> wrote in
message news:usYY3M1tIHA.576@xxxxxxxxxxxxxxxxxxxxxxx
Better off declaring nBytesRead as a DWORD is an understatement. ReadFile
is not only expecting a pointer, it is expecting a pointer to a valid
location to write the number of bytes read.
--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
EuroTech Inc.
www.EuroTech.com
"Michael Salamone" <mikesa#at#entrek#dot#com> wrote in message
news:DE3B65E3-BB3A-4CED-928C-F43C3CB16E4A@xxxxxxxxxxxxxxxx
You should know by now that you need to mention error codes. I'm
supposing you think in failed because ReadFile is returning FALSE, but
what is GetLastError() returning?
Do you have any storage allocated for inBuffer? How about nBytesRead?
One of those is probably your problem. Btw, instead of declaring
nBytesRead as "DWORD *", you'd be better off declaring it as "DWORD"
(allocates a DWORD on the stack) and passing "&nBytesRead" instead of
"nBytesRead". Otherwise you need to get storage from the heap - e.g.
nBytesRead = new DWORD or nBytesRead = (DWORD *) malloc(sizeof(DWORD)) -
something like that.
--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com
"ashishedn" <ashishedn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:31BD815B-F2C1-4523-8124-898D91B6F823@xxxxxxxxxxxxxxxx
File is getting opened after exporting the file to emulator device.
Now it is's giving error while trying to read it.
code written for that is
BOOL bResult = ReadFile(hservice,inBuffer,noofbytes,nBytesRead,NULL);
where variables are defined as.
void *inBuffer;
DWORD *nBytesRead;
DWORD noofbytes = 0x00000001;
"Michael Salamone" wrote:
You can use "Error Lookup" in VS Tools menu to check many error code
meanings. Or look in winerror.h.
Error 2 is (from winerror.h):
//
// MessageId: ERROR_FILE_NOT_FOUND
//
// MessageText:
//
// The system cannot find the file specified.
//
#define ERROR_FILE_NOT_FOUND 2L
You use OPEN_EXISTING flag. Have you verified if the file exists in
the
directory path you are using? If you are trying to create the file,
use
CREATE_ALWAYS (which will overwrite an existing file) or CREATE_NEW
(will
fail if there is an existing file) or OPEN_ALWAYS (will open an
existing
file or create a new one if no existing file). See CreateFile
reference for
more info: http://msdn.microsoft.com/en-us/library/aa914735.aspx.
--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com
"ashishedn" <ashishedn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3675C2B5-B045-4124-A61A-12369E57107A@xxxxxxxxxxxxxxxx
Yes, code is getting compiled now.However, still file is not getting
opened
and CreateFile function is returning "INVALID_HANDLE_VALUE"(DWORD
2|).
Pl. suggest.
"Erwin Zwart" wrote:
This will compile:
HANDLE hservice =
CreateFile(L"\\hi.txt",0,0,NULL,OPEN_EXISTING,0,NULL);
or
HANDLE hservice =
CreateFile((TEXT("\\hi.txt")),0,0,NULL,OPEN_EXISTING,0,NULL);
Like Michael suggested (check winnt.h).
I am not quite sure if this directory path you provide is mapped in
the
Emulator, if not it probably cannot find the file.
You might want to copy the file (hi.txt) your device's root folder
(in
this
case the emulator).
Hope this helps
Erwin Zwart
"ashishedn" <ashishedn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EB7D7F8F-291E-44A5-BCF6-68FFB1CC74C5@xxxxxxxxxxxxxxxx
When i changed my code to HANDLE hservice =
CreateFile("\\hi.txt",0,0,NULL,
OPEN_EXISTING,0,NULL);
It is giving an error - "error C2664: 'CreateFileW' : cannot
convert
parameter 1 from 'char [8]' to 'const unsigned short *'" while
compiling
the
program.
Actually what i m doing is writing a code in evc++ 4.0 and running
it
on
StandardSDK_500 emulator.For that i have copied the hi.txt file to
"C:\Program Files\Microsoft eMbedded C++ 4.0\EVC\wce500.
Ashish
"Bruce Eitman [eMVP]" wrote:
Good catch, I missed the casting.
--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
EuroTech Inc.
www.EuroTech.com
"Michael Salamone" <mikesa#at#entrek#dot#com> wrote in message
news:epTOd65sIHA.548@xxxxxxxxxxxxxxxxxxxxxxx
Just a clarification to Bruce's reply: WinCE doesn't use drive
letters.
The root is \.
One other thing we know is that casting an character string
literal
to
LPTSTR isn't going to convert it to a wide character string
which is
required for the CreateFile API call on Windows CE. Use
TEXT("\\hi.txt").
--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com
"Bruce Eitman [eMVP]" <bruce.eitman.nospam@xxxxxxxxxxxxxxxxxxx>
wrote
in
message news:uyZym25sIHA.1936@xxxxxxxxxxxxxxxxxxxxxxx
You need to give us more information than that to get
assistance
with
this kind of problem.
But clearly we can start with that you don't have a "D:\"
anything
on
a
Windows CE device. Start there. You must give a real path.
--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
EuroTech Inc.
www.EuroTech.com
"ashishedn" <ashishedn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:E58F5E5C-57BE-4968-8C80-37872B88FD2D@xxxxxxxxxxxxxxxx
Hi,
I am trying to open a .txt file through createfile function
in
eVC++
4.0.
Code written for that is
HANDLE hservice = CreateFile((LPTSTR)"D:\\hi.txt",0,0,NULL,
OPEN_EXISTING,0,NULL);
But file is not getting opened successfully.
Pl. help.
Thanks and regards,
Ashish
.
- Follow-Ups:
- Re: Opening a file.
- From: ashishedn
- Re: Opening a file.
- References:
- Opening a file.
- From: ashishedn
- Re: Opening a file.
- From: Bruce Eitman [eMVP]
- Re: Opening a file.
- From: Michael Salamone
- Re: Opening a file.
- From: Bruce Eitman [eMVP]
- Re: Opening a file.
- From: ashishedn
- Re: Opening a file.
- From: Erwin Zwart
- Re: Opening a file.
- From: ashishedn
- Re: Opening a file.
- From: Michael Salamone
- Re: Opening a file.
- From: ashishedn
- Re: Opening a file.
- From: Michael Salamone
- Re: Opening a file.
- From: Bruce Eitman [eMVP]
- Opening a file.
- Prev by Date: Re: Opening a file.
- Next by Date: Display Flicker on wince startup
- Previous by thread: Re: Opening a file.
- Next by thread: Re: Opening a file.
- Index(es):
Relevant Pages
|