CreateFileForMapping 
Author Message
 CreateFileForMapping

Hi All,

I am trying to map a binary file using
CreateFileForMapping (in a C code), but the command is not
working. It returns an invalid handle. The command looks
like this:

handle = CreateFileForMapping((LPCTSTR)filename,
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);

Unable to get out of this bug.

Regards,
Abhishek.



Tue, 05 Oct 2004 17:48:10 GMT  
 CreateFileForMapping

The code seems to be correct. I suggest that you call GetLastError after
CreateFileForMapping and see what error is reported.

--
Sincerely,
Alexander


http://www.RSDN.ru - Russian Software Developer Network


Quote:
> Hi All,

> I am trying to map a binary file using
> CreateFileForMapping (in a C code), but the command is not
> working. It returns an invalid handle. The command looks
> like this:

> handle = CreateFileForMapping((LPCTSTR)filename,
> GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
> FILE_ATTRIBUTE_NORMAL, 0);

> Unable to get out of this bug.

> Regards,
> Abhishek.



Tue, 05 Oct 2004 19:07:28 GMT  
 CreateFileForMapping
Hi,

Thanks for that. The error is "Not able to find the file".
filename is a char* and I have casted it to LPCTSTR. As my
application is veyr big, so I cannot change all chars to
TCHARS/wchar_t. Thus, I will have to live with a char
somehow. Please suggest how to make CreateFileForMapping
find the file. fopen etc. work fine with char* filenames.

Regards,
Abhishek

Quote:
>-----Original Message-----

>The code seems to be correct. I suggest that you call
GetLastError after
>CreateFileForMapping and see what error is reported.

>--
>Sincerely,
>Alexander


>http://www.RSDN.ru - Russian Software Developer Network


message

>> Hi All,

>> I am trying to map a binary file using
>> CreateFileForMapping (in a C code), but the command is
not
>> working. It returns an invalid handle. The command looks
>> like this:

>> handle = CreateFileForMapping((LPCTSTR)filename,
>> GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
>> FILE_ATTRIBUTE_NORMAL, 0);

>> Unable to get out of this bug.

>> Regards,
>> Abhishek.

>.



Tue, 05 Oct 2004 22:35:06 GMT  
 CreateFileForMapping
Make the API to do what you want it to do?  Wouldn't that be nice...  Nice
try, though.

Actually, you can make it do what you want to by passing a wchar *.

Make a wrapper function - maybe CreateFileForMappingA() that does take a
char* and converts it wchar * - then call the system CreateFileForMapping().

So you don't have to change every call you make to CreateFileForMapping, you
could further put this line in a common header file:

#define CreateFileForMapping   CreateFileForMappingA

--
Michael Salamone
Entrek Software, Inc.
http://www.entrek.com


Quote:
> Hi,

> Thanks for that. The error is "Not able to find the file".
> filename is a char* and I have casted it to LPCTSTR. As my
> application is veyr big, so I cannot change all chars to
> TCHARS/wchar_t. Thus, I will have to live with a char
> somehow. Please suggest how to make CreateFileForMapping
> find the file. fopen etc. work fine with char* filenames.

> Regards,
> Abhishek

> >-----Original Message-----

> >The code seems to be correct. I suggest that you call
> GetLastError after
> >CreateFileForMapping and see what error is reported.

> >--
> >Sincerely,
> >Alexander


> >http://www.RSDN.ru - Russian Software Developer Network


> message

> >> Hi All,

> >> I am trying to map a binary file using
> >> CreateFileForMapping (in a C code), but the command is
> not
> >> working. It returns an invalid handle. The command looks
> >> like this:

> >> handle = CreateFileForMapping((LPCTSTR)filename,
> >> GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
> >> FILE_ATTRIBUTE_NORMAL, 0);

> >> Unable to get out of this bug.

> >> Regards,
> >> Abhishek.

> >.



Tue, 05 Oct 2004 23:12:40 GMT  
 CreateFileForMapping

Yes, C functions can work with char*, but API functions (on WinCE) - can't.
There are many functions and wrappers to convert from ANSI to UNICODE. One
option is to use ATL conversion macros, e. g.:

USES_CONVERSION;
CreateFileMapping(A2T("<filename in ANSI>"), ...);

--
Sincerely,
Alexander


http://www.RSDN.ru - Russian Software Developer Network


Quote:
> Hi,

> Thanks for that. The error is "Not able to find the file".
> filename is a char* and I have casted it to LPCTSTR. As my
> application is veyr big, so I cannot change all chars to
> TCHARS/wchar_t. Thus, I will have to live with a char
> somehow. Please suggest how to make CreateFileForMapping
> find the file. fopen etc. work fine with char* filenames.

> Regards,
> Abhishek

> >-----Original Message-----

> >The code seems to be correct. I suggest that you call
> GetLastError after
> >CreateFileForMapping and see what error is reported.

> >--
> >Sincerely,
> >Alexander


> >http://www.RSDN.ru - Russian Software Developer Network


> message

> >> Hi All,

> >> I am trying to map a binary file using
> >> CreateFileForMapping (in a C code), but the command is
> not
> >> working. It returns an invalid handle. The command looks
> >> like this:

> >> handle = CreateFileForMapping((LPCTSTR)filename,
> >> GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
> >> FILE_ATTRIBUTE_NORMAL, 0);

> >> Unable to get out of this bug.

> >> Regards,
> >> Abhishek.

> >.



Tue, 05 Oct 2004 23:34:10 GMT  
 CreateFileForMapping


Quote:
> Hi,

> Thanks for that. The error is "Not able to find the file".
> filename is a char* and I have casted it to LPCTSTR. As my
> application is veyr big, so I cannot change all chars to
> TCHARS/wchar_t. Thus, I will have to live with a char
> somehow. Please suggest how to make CreateFileForMapping
> find the file. fopen etc. work fine with char* filenames.

You should be aware that CE's object store is compressed - even for binary
files like executables - I believe on a per-block basis.  There are two
algorithms used - a GZIP/ZIP-like algorithm that is applied to the whole
block in one go, and another algorithm that splits the block into odd and
even bytes.  This second algorithm then applies the same compression
algorithm to the odd and even byte streams independently.

What this tends to mean for a block of Unicode text using only Latin-1
characters is that the even bytes (CE devices are all currently
little-endian) are almost always zero.  A very long block of zeros tends to
compress to an extremely small size.

Frankly, you might as well stick to UNICODE strings - the overhead isn't
that critical, and most operations require a UNICODE string, which usually
means that your process's memory or stack usage goes up as the OS has to
convert the string before calling the underlying function.

fopen is a C run-time library routine, and takes an ANSI string as its
parameter.  All it does, IIRC, is convert the string to UNICODE, then call
_wfopen.

--
Mike Dimmick



Wed, 06 Oct 2004 02:15:08 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. CreateFileForMapping

 

 
Powered by phpBB® Forum Software