Article View: borland.public.cppbuilder.nativeapi
Article #16494Re: Help with Mapping a file into memory
From: Remy Lebeau (TeamB)
Date: Sun, 11 May 2003 05:56
Date: Sun, 11 May 2003 05:56
41 lines
2047 bytes
2047 bytes
"Ray" <raymondlewis@beeb.net> wrote in message
news:3ebd068b@newsgroups.borland.com...
> Have had a look at CreateFileMapping() and
> MapViewofFile() in the API Help
Those are the correct functions to use, yes.
> I find them a little confusing especially as there are
> no examples that show the usage of the data in the
> way I want.
Here you go:
HANDLE hFile = CreateFile(...);
if( hFile != INVALID_HANDLE_VALUE )
{
HANDLE hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0,
0, NULL);
if( hMapping != NULL )
{
LPBYTE lpData = (LPBYTE) MapViewOfFile(hMapping, FILE_MAP_READ,
0, 0, 0);
if( lpData != NULL )
{
// use lpData as needed, not to exceed the size of
// the file. You can use can use GetFileSize() if you
// need to determine the size of the file ahead of time
UnmapViewOfFile(lpData);
}
CloseHandle(hMapping);
}
CloseHandle(hFile);
}
Gambit
Technical Details
Message-ID:
<3ebde597$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ebd068b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,54763ae38339041 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-10 22:55:58 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ebd068b@newsgroups.borland.com> Subject: Re: Help with Mapping a file into memory Date: Sat, 10 May 2003 22:56:26 -0700 Lines: 43 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3ebde597$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1052632471 207.175.226.26 (10 May 2003 22:54:31 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail