Home > Archive > Smartphone Developer Forum > March 2006 > CreateFileMapping problem.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
CreateFileMapping problem.
|
|
| Stoking 2006-03-28, 10:50 am |
| code: DWORD err;
HANDLE hFile=CreateFile(_T("\\Storage Card\\1.txt"),GENERIC_WRITE | GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATT
RIBUTE_NORMAL,NULL);
err=GetLastError();
HANDLE hFileMapping=CreateFileMapping(hFile,NUL
L,PAGE_READWRITE,0,200,_T("DATAFILE"));
err=GetLastError();
If \\Storage Card\\1.txt exists, the code works.
But if the file doesn't exist, CreateFileMapping returns 0, and the last GetLastError returns 5.
Why? How can i make CreateFileMapping return a valid handle while \\Storage Card\\1.txt doesn't not exist?
And another question. If I set the parameter dwMaximumSizeLow of CreateFileMapping to 200, the size of \\Storage Card\\1.txt increases to 200 bytes after running the program. But if I set the parameter to 0, and I want to append something to the end of the file, what should I do? | |
| Michael J. Salamone 2006-03-29, 4:11 am |
| Do not use CreateFile to open a handle you pass to CreateFileMapping. WinCE
is incompatible with Win32 in this regard. Use CreateFileForMapping
instead. Look at the help to note the CloseHandle semantics as these are
different for WinCE to (compared to Win32).
I'm not sure how it's working for you when the file exists. And I don't
know that CreateFileForMapping would solve the problem when the file does
not exist (I doubt it would).
--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com
"Stoking" <Stoking.25eoy3@mail.codecomments.com> wrote in message
news:Stoking.25eoy3@mail.codecomments.com...
>
>
> Code:
> --------------------
> DWORD err;
> HANDLE hFile=CreateFile(_T("\\Storage Card\\1.txt"),GENERIC_WRITE |
> GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATT
RIBUTE_NORMAL,NULL);
> err=GetLastError();
> HANDLE
> hFileMapping=CreateFileMapping(hFile,NUL
L,PAGE_READWRITE,0,200,_T("DATAFILE"));
> err=GetLastError();
> --------------------
>
>
>
> If \\Storage Card\\1.txt exists, the code works.
>
> But if the file doesn't exist, CreateFileMapping returns 0, and the
> last GetLastError returns 5.
>
> Why? How can i make CreateFileMapping return a valid handle while
> \\Storage Card\\1.txt doesn't not exist?
>
> And another question. If I set the parameter dwMaximumSizeLow of
> CreateFileMapping to 200, the size of \\Storage Card\\1.txt increases
> to 200 bytes after running the program. But if I set the parameter to
> 0, and I want to append something to the end of the file, what should I
> do?
>
>
>
> --
> Stoking
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>
|
|
|
|
|