Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Using shared memory in Win32 applications

Posted on 1999-01-06
10
206 Views
Last Modified: 2010-04-02
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?
0
Comment
Question by:arbitrary
10 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1181632
Try the WM_COPYDATA message.  It is the easiest way to pass data between applications.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1181633
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"?  
0
 
LVL 1

Author Comment

by:arbitrary
ID: 1181634
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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 22

Expert Comment

by:nietod
ID: 1181635
>> 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?
0
 
LVL 86

Expert Comment

by:jkr
ID: 1181636
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

SECTIONS
shared READ WRITE SHARED

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)'...
0
 
LVL 3

Expert Comment

by:stefanr
ID: 1181637
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.
0
 
LVL 1

Author Comment

by:arbitrary
ID: 1181638
nietod method  is the most satisfiable,
i reckon you should get the points .

0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1181639
Then I'm answering again, but did you try it? Is it working?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1181640
So, what is happening, is this working?
0
 
LVL 1

Author Comment

by:arbitrary
ID: 1181641
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,
thanx.
oh sorry it took a long time i just completely forgot 'bout it.
so there you go
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

860 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