Solved

Passing an object between processes

Posted on 1998-08-21
4
205 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
[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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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