vc++ 共享內存

// 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;

}


// 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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章