Solved

Passing an object between processes

Posted on 1998-08-21
4
199 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 100 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now