当前位置:编程学习 > VC++ >>

进程间共享内存

//////////程序一的代码 HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,4*1024,"test"); if (hMapFile == NULL) { cout<<"CreateFileMapping failed!"<<endl; } char*p= (char*)MapViewOfFile(hMapFile,FILE_MAP_ALL_ACCESS,0,0,0); if (p == NULL){ cout<<"MapViewOfFile failed!"<<endl; } else {p[0]=00; } //////////程序二的代码: HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS,false,"test"); if (hMapFile == NULL) {cout<<"OpenFileMapping failed!"<<endl;} char* p = (char*)MapViewOfFile(hMapFile,FILE_MAP_ALL_ACCESS,0,0,0); if (p == NULL){cout<<"MapViewOfFile faild!"<<endl;} else { cout<<p[0]<<endl; }; } 在程序一中创建进程调用程序2,发现每次都 OpenFileMapping failed! MapViewOfFile faild! 如果程序2的函数放在程序1里面执行就可以成功,但是我需要进程间的共享, 现在还在摸索当中,不知道如何在程序2得到程序1的那个指针p 敬请赐教~ 问题补充:主要的函数 CreateFileMapping MapViewOfFile OpenFileMapping
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,