内存共享函数OpenFileMapping,在release模式下返回NULL
来源:互联网 发布:阿里云服务器安全问题 编辑:程序博客网 时间:2024/05/18 02:39
共享内存的步骤为:CreateFileMapping创建共享的内存空间;OpenFileMapping打开共享内存,返回HANDLE型句柄;MapViewOfFile获取内存映射到该程序的内存,可以进行读写操作。
在实验中遇到了意外的情况,具体应用情景为:win10环境下使用共享内存在两个不同程序之间传递数据。在release模式下第二个程序调用OpenFileMapping始终返回NULL。
使用getLastError函数返回错误2:系统找不到指定文件。
查看了微软OpenFileMapping官方文档(链接),里面有一段话:
The name of the file mapping object to be opened. If there is an open handle to a file mapping object by this name and the security descriptor on the mapping object does not conflict with the dwDesiredAccess parameter, the open operation succeeds. The name can have a "Global\" or "Local\" prefix to explicitly open an object in the global or session namespace. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Namespaces. Fast user switching is implemented using Terminal Services sessions. The first user to log on uses session 0, the next user to log on uses session 1, and so on. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users. 没怎么看懂,应该是和windows程序管理有关吧,好像是win7之后没有界面的程序视为“服务”,运行在系统的session 0(session 0参考这里),和我的另一个程序运行的命名空间是不一样的,所以要在共享内存名前面加上"Global\",问题就解决了。
char * name = "Global\ShareMemory";看一下效果吧:
0 0
- 内存共享函数OpenFileMapping,在release模式下返回NULL
- 在Debug模式下中断, 在Release模式下跳出当前函数的断言
- 在Release模式下的调试
- 怎么在Release模式下调试代码
- VS2015在release模式下进行调试
- VS2015在release模式下进行调试
- malloc函数申请内存失败,返回空NULL(0)
- fastdb 共享内存模式下的限制
- MFC+OpenCV Debug正常Release模式下内存错误
- Linux下共享内存相关函数
- CreateWindow函数返回NULL
- 在release模式下使用vector下崩溃的问题
- system v 共享内存 相关函数及返回值 描述
- VS2013 IDE环境 OPENCV3.0.0以上依赖库环境 findContour 函数在Release模式下出现异常解决办法之一
- VS2005设置可以在Release模式下调试
- VS2005设置可以在Release模式下调试
- VS2005设置可以在Release模式下调试
- VS2005设置可以在Release模式下调试
- Android 6.0运行时获取权限详解
- java.util.ConcurrentModificationException解决办法
- Google Guava-缓存
- 【Android 初学者】权限调用,手把手教你们启用权限
- 然后Denton et al, 2015 搞出了非常NB的改进版本
- 内存共享函数OpenFileMapping,在release模式下返回NULL
- 数据分库,横向切分,纵向切分
- Dlib提取人脸特征点(68点,opencv画图)
- Javascript之数据类型以及一些常用方法
- Git与SVN区别
- 12月2日:一周最受关注论文排行榜
- 21分钟 MySQL 入门教程
- 在Dell XPS 13安装WIN10和ubuntu双系统
- UIKit-TableView--TableView用代码自定义cell