// ShareMemory1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include <Windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 255, _T("fool2003"));
TCHAR* ptChar = (TCHAR* )MapViewOfFile(hFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
memcpy(ptChar, _T("HelloWorldYuanhs"), sizeof( _T("HelloWorldYuanhs") ) );
getchar();
return 0;
//
#include "stdafx.h"
#include<iostream>
#include <Windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 255, _T("fool2003"));
TCHAR* ptChar = (TCHAR* )MapViewOfFile(hFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
memcpy(ptChar, _T("HelloWorldYuanhs"), sizeof( _T("HelloWorldYuanhs") ) );
getchar();
return 0;
}
// ShareMemory2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char* pTemp = "11111";
std::cout<<pTemp<<endl;
HANDLE hFileMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, _T("fool2003"));
TCHAR* ptChar = (TCHAR* )MapViewOfFile(hFileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
std::wstring s(ptChar);
std::wcout<<s.c_str();
getchar();
return 0;
}