vc++ 共享内存

来源:互联网 发布:xp电脑网络起动慢 编辑:程序博客网 时间:2024/06/05 01:02
// 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;
}

原创粉丝点击