0
votes

I have a DLL that uses memory-mapped files to provide data sharing among multiple processes in Windows (C++). Processes that want to read/write data to each other register their window handles with the DLL. When one of them puts data into the share, the others are notified. Any process may read or write data via the DLL.

I'd like to be able to prevent processes from writing to the shared memory until the notification is complete, prevent multiple processes from writing at the same time, etc. It feels like I need a "global mutex", but is there such a thing?

Thanks.

1

1 Answers

0
votes

Use "virtuallock" WinAPI function.

The inputs are your mapped memory pointer and mapped memory size.

BOOL WINAPI VirtualLock(
  _In_ LPVOID lpAddress,
  _In_ SIZE_T dwSize
);

You have VirtualUnlock to unclock the memory, whenever you want to (based on your business requirements)

To understand more about it, please refer winAPI documentation.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa366895(v=vs.85).aspx