如何用CreateFileMapping实现进程之间共享数据
HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,4*1024,"XQ");
if (hMapFile == NULL)
{
MessageBox(NULL,"程序异常!","信息",MB_OK);
}
LPVOID lpMapAddress = MapViewOfFile(hMapFile,FILE_MAP_ALL_ACCESS,0,0,0);
if (lpMapAddress == NULL)
{
MessageBox(NULL,"程序异常!","信息",MB_OK);
}
else
{
char szPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,szPath);
(char *)lpMapAddress = szPath;
UnmapViewOfFile(lpMapAddress);
}
HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS,false,"XQ");
if (hMapFile == NULL)
{
MessageBox(NULL,"程序异常","信息",MB_OK);
}
LPVOID lpMapAddress = MapViewOfFile(hMapFile,FILE_MAP_ALL_ACCESS,0,0,0);
if (lpMapAddress == NULL)
{
MessageBox(NULL,"程序异常","信息",MB_OK);
}
else
{
Form2->Caption = AnsiString((char *)lpMapAddress); //这边得到的不是上面的值
UnmapViewOfFile(lpMapAddress);
}
[注意]APP应用上架合规检测服务,协助应用顺利上架!