• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Using shared memory in Win32 applications

I want to use simple windows messaging with a buffer of text
the allocation should be global yet there's a problem to use GlobalAlloc since it no longer shares memory between applications.
I also used CreateFileMapping but this solution is too dependent it won't solve my problem. any suggestions?
1 Solution
Try the WM_COPYDATA message.  It is the easiest way to pass data between applications.
However, if you want to go with the file mapping, you should be able to.  I can see no reason why a file mapping won't work.  What do you mean by it is "too dependant"?  
arbitraryAuthor Commented:
WM_COPYDATA needs a structure for data - COPYDATASTRUCT
it has 3 var in it - dwData cbData and lpData
I tried to assign the Data pointer (char* ) to the dwData and to
lpData , I know the value of the pointer is value yet there was
a memory violation as if it was null.
i tried to use file mapping but there's synchronization problems with it , which i can't base on synchronizing it since it will make my application less robust.
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

>> I tried to assign the Data pointer (char* ) to the dwData and to
>>  lpData , I know the value of the pointer is value yet there was
You must have done somethig wrong, can you post the code that sent the message and also the code that receives it?

>> which i can't base on synchronizing it
>> since it will make my application less robust.
synchronization will make your application more robust, not less.  What sort of problem were you having or you thought you were having?
What about a DLL that exports a shared memory section, e.g.

#pragma data_seg( ".shared")
// shared data goes here
char acSharedCharArray [ SHARED_ARRAY_SIZE] = "\0";
// initialization _is_ necessary
#pragma data_seg()

link using


in the .def file

Then, export 2 functions from this DLL that allow synchronized access to the data, e.g. 'BOOL SetData( char* pcData, long lnLen)' and 'long GetData( char* pcBuffer, long lnLen)'...
Another way of sharing data between applications besides WM_COPYDATA (easiest), memory mapped files (most powerful), and a shared DLL data segment is to use the network functions, like a named pipe, NetBios or TPC/IP.
arbitraryAuthor Commented:
nietod method  is the most satisfiable,
i reckon you should get the points .

Then I'm answering again, but did you try it? Is it working?
So, what is happening, is this working?
arbitraryAuthor Commented:
I've tried it and so far it works as good as it can get ,
I think it's good since the i don't need to synchronize between the proccesses .
As I said it's the most satisfying solution,
oh sorry it took a long time i just completely forgot 'bout it.
so there you go
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now