Windows 7中的DLL共享内存 [英] DLL Shared Memory in Windows 7

查看:139
本文介绍了Windows 7中的DLL共享内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个可以在Windows XP上运行多年的应用程序,没有任何问题.
现在,我必须将其移植到Win7.

该应用程序包括我用C语言编写的Windows服务.该服务在LOCAL SYSTEM帐户下运行,并使用DLL,我的其他一些应用程序也使用了该DLL.
有些应用程序是用C编写的,而有些则是用VB编写的. DLL使用CreateFileMapping()为所有客户端创建一个共享内存区域.在Windows XP上,所有客户端都可以看到共享内存区域的相同副本,以便一个应用程序可以更改变量的值,而所有其他应用程序可以看到新值.

现在,在Windows 7中,客户端似乎无法看到与ServiceApp相同的共享内存区域.就像ServiceApp拥有自己的共享内存专用副本一样.

这可能与Microsoft更改Vista和Win7的会话ID"行为的方式有关吗?我的ServiceApp的会话ID = 0,客户端的会话ID = 1.
在XP上,它们都是Session ID = 0.

有什么简单的方法可以解决此限制.

I wrote an app that has been running on Windows XP for years with no issues.
Now I have to port it over to Win7.

The app includes a Windows Service that I wrote in C. The service runs under the LOCAL SYSTEM account and uses a DLL that is also used by some of my other apps.
Some of the apps are written in C and some in VB. The DLL creates a shared memory area for all clients using CreateFileMapping(). On Windows XP all clients can see the same copy of the shared memory area so that one app can change a variable''s value and all other apps can see the new value.

Now with Windows 7 the clients don''t seem to be able to see the same shared memory area that the ServiceApp sees. It is as if the ServiceApp has its own private copy of the shared memory.

Could this be related to the way Microsoft changed the "Session ID" behavior for Vista and Win7? My ServiceApp has Session ID=0 and the clients are Session ID=1.
On XP they were all Session ID=0.

Is there an easy way around this restriction.

推荐答案

调用CreateFileMapping使用的名称是什么?您是否使用过"Global \"前缀将其强制进入全局名称空间?

另请参见 http://msdn.microsoft.com/en-us/library/aa382954.aspx [ ^ ]进行了有关SeCreateGlobalPrivilege您将需要的.
What name are you using for the call to CreateFileMapping? Have you used the "Global\" prefix to force it into the global namespace?

See also http://msdn.microsoft.com/en-us/library/aa382954.aspx[^] for a discussion about the SeCreateGlobalPrivilege that you will need.


Sauro,根据我的阅读,对于内存映射文件和共享数据段,您说的是TRUE.正确的? 有关共享内存的MSDN文章 [
Sauro, from what I have read, what you say is TRUE for memory mapped files AND shared data segments. Correct? MSDN Article on Shared Memory[^]


如果您想使用内存映射文件,我怀疑您需要做的另一件事是使用NULL DACL调用CreateFileMapping作为安全属性(与将NULL作为参数值传递不同).
The other thing I suspect you would need to do, if you wanted to use memory-mapped files, would be to call CreateFileMapping with a NULL DACL for the security attributes (not the same as passing NULL in as the parameter value).


这篇关于Windows 7中的DLL共享内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆