Solved

Using shared memory in Win32 applications

Posted on 1999-01-06
10
212 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
[X]
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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

705 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