关闭

vc++ 共享内存

535人阅读 评论(0) 收藏 举报
分类:
// 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;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:55902次
    • 积分:1097
    • 等级:
    • 排名:千里之外
    • 原创:45篇
    • 转载:56篇
    • 译文:0篇
    • 评论:0条
    文章分类