[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using shared memory in Win32 applications

Posted on 1999-01-06
10
Medium Priority
?
214 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

649 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