Solved

Shared Memory and inheritance

Posted on 1998-03-27
1
204 Views
Last Modified: 2013-12-03
I am currently using CreateFileMapping() and MapViewOfFile() to create a block of shared memory using 0xFFFFFFFF as the first parameter of the CreatFileMapping() call so its not associated with a file but uses the system paging file.



However, by giving it a name "MY_SHARED_MEM", so both processes will attach to the same area, this leaves me with a problem.



At some point in time, these applications may run on an NT server and so there may be multiple processes running. I only want the main process and the child process *of that main process* to access the shared memory. As it is, I 'think' that if another uses starts a 2nd main process and launches the child, they will attach to the original area, becuase of the name correct?



How can I avoid this, and yet still use the system paging file? . use the CreateProcess to launch the child with handle inheritance set to TRUE if thats necessary to do this. I've read about DuplicateHandle() but not sure how to set it up..can't quite get a grasp on it.



Any help would be appreciated
0
Comment
Question by:gunn
1 Comment
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 110 total points
ID: 1412338
This is not that unusual. One idea is to not hardcode a specific name, but to use one based off of the processId of the parent. For example, instead of using MY_SHARED_MEM as the name of the filemap, use MY_SHARED_MEM_%PROCESSID%. Then when the parent process launches the child, pass the child the name as an argument.

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question