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
Solved

Passing an object between processes

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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