dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Sending a message to another application

  1. #1
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    188

    Sending a message to another application

    Hey Gurus!

    I have written two pieces of software using MFC dialog based classes. One of them creates DCPs for digital cinema, and the other checks the integrity of DCPs.
    I would like my first program to talk to my second program with a single one way message.
    To do this I am using PostMessage, and my second program is receiving the message with no issues at all. The trouble is, I can't read the data I am sending.

    Here is my code, firstly the program sending the message:

    Code:
    HWND dcpProbe = ::FindWindow( 0, "DCPProbe" );
    
    if ( dcpProbe )
    {
    	char *message;
    
    	message = ( char * ) malloc( sizeof( "Hello World" ) );
    
    	strcpy( message, "Hello World" );
    
    	if ( !::PostMessage( dcpProbe, DCPPRO_ANALYSEDCP, ( WPARAM ) NULL, ( LPARAM ) message ) ) free( message );
    }
    An now the program receiving the message:

    Code:
    ON_MESSAGE( DCPPRO_ANALYSEDCP, DCPProAnalyseDCP )
    
    afx_msg LRESULT CDCPProbeDlg::DCPProAnalyseDCP( WPARAM param1, LPARAM param2 )
    {
    	char *parameters;
    	
    	parameters = ( char * )param2;
    
    	// Do things with parameters.
    
    	// free( parameters ); // Do this once I have handled the message
    
    	return false;
    }
    I have printed out the pointer being sent, and when I run the receiving program in debug, the memory pointer I receive is correct!! However the debugger says:

    parameters: 0x07b82870 <Error reading characters of string>
    <Unable to read memory>


    I am confused as to why this is the case?
    The first program is not UNICODE, however the second is UNICODE, although I doubt this is a problem.

    If someone could please offer me some advice, I'd be very grateful.

    Thanks so much,

    Steve Q.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,579

    Re: Sending a message to another application

    It is because you post a pointer to the buffer with data. This pointer is only valid in context of the posting application and is invalid for any other one.
    Try to use WM_COPYDATA instead. Read this essay about using WM_COPYDATA.
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    188

    Re: Sending a message to another application

    Thanks heaps Victor.

    This appears to be working now.

    I really appreciate your help.

    Thanks again,

    Steve Q.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)