Solved

Sending Messages to Windows in another process

Posted on 2003-12-04
2
453 Views
Last Modified: 2013-11-20
Hi

I have a .exe which receives data on a serial port, does some checking and formatting and passes the data on.
Its dedicated task is just this, however I need to send the data to another application (.exe) so that it can render
the data for graphical display. Is it possible to send/post to the HWND of the second app. i.e. from process A to
process B. What implications for the data? simple strings!

Another way I thought was to use sockets and pass the data this way, does anyone know of
any better ways to acheive this?

Thanks

LittlePerson
0
Comment
Question by:LittlePerson
[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 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 35 total points
ID: 9874286
I hope you have the source code of the second process and can write both sending and receiving functions.
When you send (or better, post) data to another process, you cannot pass pointers since each process has it's own address space and pointer passed to another process is invalid. All data posted using Windows message should be contained in (wParam, lParam).
To pass strings (and any other data) you should use inter-process communications (IPC).

Using memory-mapped files for IPC:
http://www.codeproject.com/threads/ipc_tute.asp

Various ways of APC:
http://www.codeproject.com/threads/#Inter%2DProcess+Communication


0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 40 total points
ID: 9874288
Use SendMessage with *WM_COPYDATA*, that is the recommended way.

MSDN Sample

// ************ Globals ************

#define MYDISPLAY 1

typedef struct tagMYREC
{
   char  s1[80];
   char  s2[80];
   DWORD n;
} MYREC;

COPYDATASTRUCT MyCDS;
MYREC MyRec;

BOOL CALLBACK InfoDlgProc( HWND, UINT, WPARAM, LPARAM );

// ************ Code fragment ****************

// Get data from user. InfoDlgProc stores the information in MyRec.

   DialogBox( ghInstance, "InfoDlg", hWnd, (DLGPROC) InfoDlgProc );

// Copy data into structure to be passed via WM_COPYDATA

   lstrcpy( MyRec.s1, szFirstName );
   lstrcpy( MyRec.s2, szLastName );
   MyRec.n = nAge;

// Fill the COPYDATA structure

   MyCDS.dwData = MYPRINT;          // function identifier
   MyCDS.cbData = sizeof( MyRec );  // size of data
   MyCDS.lpData = &MyRec;           // data structure

// Call function, passing data in &MyCDS

   hwDispatch = FindWindow( "Disp32Class", "Hidden Window" );
   if( hwDispatch != NULL )
      SendMessage( hwDispatch,
                   WM_COPYDATA,
                   (WPARAM)(HWND) hWnd,
                   (LPARAM) (LPVOID) &MyCDS );
   else
      MessageBox( hWnd, "Can't send WM_COPYDATA", "MyApp", MB_OK );
The receiving application has a hidden window which receives the information from WM_COPYDATA and displays it to the user.

// ************ Globals ************

#define MYDISPLAY 1

typedef struct tagMYREC
{
   char  s1[80];
   char  s2[80];
   DWORD n;
} MYREC;

PCOPYDATASTRUCT pMyCDS;

void WINAPI MyDisplay( LPSTR, LPSTR, DWORD );

// ************ Code fragment ****************

case WM_COPYDATA:
   pMyCDS = (PCOPYDATASTRUCT) lParam;

   switch( pMyCDS->dwData )
   {
      case MYDISPLAY:
         MyDisplay( (LPSTR) ((MYREC *)(pMyCDS->lpData))->s1,
                    (LPSTR) ((MYREC *)(pMyCDS->lpData))->s2,
                    (DWORD) ((MYREC *)(pMyCDS->lpData))->n );
   }
   break;


Rosh :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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