--000000000000360e1d05b0c39194
Content-Type: text/plain; charset="UTF-8"
hi guys i try to read a memory mapped file created with c++ , this is a c++
code that i have
[code]
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#define BUF_SIZE 256
TCHAR szName[] = TEXT("MyFileMappingObject");
TCHAR szMsg[] = TEXT("Message from first process.");
int _tmain()
{
HANDLE hMapFile;
LPCTSTR pBuf;
hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
BUF_SIZE, // maximum object size (low-order DWORD)
szName); // name of mapping object
if (hMapFile == NULL)
{
_tprintf(TEXT("Could not create file mapping object (%d).\n"),
GetLastError());
return 1;
}
pBuf = (LPTSTR)MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
_tprintf(TEXT("Could not map view of file (%d).\n"),
GetLastError());
CloseHandle(hMapFile);
return 1;
}
CopyMemory((PVOID)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR)));
_getch();
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
return 0;
}
[/code]
how can read a memory mapped created ?
thankz at all
--000000000000360e1d05b0c39194
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>hi guys i try to read a memory mapped file created wi=
th c++ , this is a c++ code that i have <br></div><div>[code]</div><div>#in=
clude <windows.h><br>#include <stdio.h><br>#include <conio.h=
><br>#include <tchar.h><br><br>#define BUF_SIZE 256<br>TCHAR szNam=
e[] =3D TEXT("MyFileMappingObject");<br>TCHAR szMsg[] =3D TEXT(&q=
uot;Message from first process.");<br><br>int _tmain()<br>{<br>=C2=A0 =
=C2=A0 HANDLE hMapFile;<br>=C2=A0 =C2=A0 LPCTSTR pBuf;<br><br>=C2=A0 =C2=A0=
hMapFile =3D CreateFileMapping(<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 INVALID_HAN=
DLE_VALUE, =C2=A0 =C2=A0// use paging file<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 N=
ULL, =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/=
/ default security<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 PAGE_READWRITE, =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0// read/write access<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 0, =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 // maximum object size (high-order DWORD)<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 BUF_SIZE, =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0// maximum object size (low-order DWORD)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
szName); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // name of=
mapping object<br><br>=C2=A0 =C2=A0 if (hMapFile =3D=3D NULL)<br>=C2=A0 =
=C2=A0 {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 _tprintf(TEXT("Could not creat=
e file mapping object (%d).\n"),<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 GetLastError());<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 1;<br>=C2=A0=
=C2=A0 }<br>=C2=A0 =C2=A0 pBuf =3D (LPTSTR)MapViewOfFile(hMapFile, =C2=A0 =
// handle to map object<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 FILE_MAP_ALL_ACCESS,=
// read/write permission<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 0,<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 0,<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 BUF_SIZE);<br><br>=C2=
=A0 =C2=A0 if (pBuf =3D=3D NULL)<br>=C2=A0 =C2=A0 {<br>=C2=A0 =C2=A0 =C2=A0=
=C2=A0 _tprintf(TEXT("Could not map view of file (%d).\n"),<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 GetLastError());<br><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 CloseHandle(hMapFile);<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 return 1;<br>=C2=A0 =C2=A0 }<br><br><br>=C2=A0 =C2=A0 CopyMemory((PVOID=
)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR)));<br>=C2=A0 =C2=A0 _getch();=
<br><br>=C2=A0 =C2=A0 UnmapViewOfFile(pBuf);<br><br>=C2=A0 =C2=A0 CloseHand=
le(hMapFile);<br><br>=C2=A0 =C2=A0 return 0;<br>}</div><div>[/code]</div><d=
iv><br></div><div>how can read a=C2=A0 memory mapped created ? <br></div><d=
iv>thankz at all</div><div><br></div></div>
--000000000000360e1d05b0c39194--