Solved

Passing an object between processes

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 90
Tab names are off by one 5 54
withoutTen challenge 14 121
how to use laptop or pad camera in vb.net windows application 2 71
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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