Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing an object between processes

Posted on 1998-08-21
4
Medium Priority
?
213 Views
Last Modified: 2013-11-20
I have two vc++ applications that communicate using a
named pipe.  I would like to send some local variable
values down the pipe from the client to the server.  At
present the only way I have achieved this successfully
is to convert the values to one long character string.  As I have encapsulated the variables into a container class, I would like to pass the whole container object by value down the pipe.  How do I do this?  Is there an easier/better method than using pipes?
0
Comment
Question by:kenick
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1321124
I would suggest using File Mapping. File Mapping allows two or more applications to share memory. Look into the documentation about File Mapping.
0
 

Author Comment

by:kenick
ID: 1321125
Thats a possibility, but can you do this with pipes?  I have all the code inplace for pipe communication.  All I would like to know is how to convert an active object (or its data members) to a byte stream.
0
 
LVL 2

Accepted Solution

by:
jstolan earned 200 total points
ID: 1321126
There are a LOT of different interprocess communication methods.  Here is one I use for a similar problem.  It is also similar to the usual drag-and-drop technique.

First lock and load an area of global data, something like this

// Allocate plenty of memory
HGLOBAL hgData =
    GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT,
                sizeof(Object) );
// lock it
LPTSTR lpData = (LPTSTR)GlobalLock( hgData );
// **** Now  fill it with data here ****
// Unlock the data
GlobalUnlock( hgData );

Now you can simply send the Global handle down the pipe, or any other interprocess communication method you want.

On the other end, lock the global handle, read the data and then free the global memory.

0
 
LVL 23

Expert Comment

by:chensu
ID: 1321127
jstolan,

Does it work in Win32?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2
Suggested Courses

824 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