[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SendMessage - Clarification on Properly Using the WPARAM and LPARAM Parameters

Posted on 2004-10-20
3
Medium Priority
?
816 Views
Last Modified: 2013-12-03
I am planning on using the wparam and lparam parameters of SendMessage to send small bits
of data between two Windows applications on the same machine.  The types and forms of the
data are as follows:

* int - between four to six digits
* string - between two to three characters

In addition, the applications will be using a Windows message that I will be defining using
RegisterWindowMessage.  My questions are as follows:

* Are there any problems associated with this technique?
* How do I pass these types of data into SendMessage?  Do I pass them in directly or do I
have to cast them?
* How do I retrieve these types of data from the retrieving application?

Finally, I am programming in C using Windows .Net.  Any help is appreciated.  Please
provide code samples with your explanation if applicable.
0
Comment
Question by:jtrades
[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
3 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 12364817
0
 
LVL 8

Expert Comment

by:mxjijo
ID: 12365045

>> Are there any problems associated with this technique?
     No, it should work !

>> How do I pass these types of data into SendMessage?
     You don't it is generic! Its the agreement between the sending function and the receiving function.
On other words, the receiving function knows what type LPARAM and WPARAM are, it it type casts them accordingly.
If you pass more than one params, then make a structure and pass the address of the structure as LPARAM/WPARAM.
Hope you know that LPARAM and WPARAM are kind of same the only diff is WPARAM is long and LPARAM is unsigned long.

>>Do I pass them in directly or do I have to cast them?
    Typecast them.

Example:

typedef struct _SAMPLE
{
     int IntField;
     char szCharField[80];
}SAMPLE, *PSAMPLE;


Sending Functtion:
PSAMPLE pSendSample = new SAMPLE;
SendMessage(hWindow, WM_MY_MSG , (WPARAM)pSendSample, 0);



Receiving function:
WindowProc( HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
{
    case  WM_MY_MSG :
    PSAMPLE pSample = (PSAMPLE)wParam;
    if (pSample)
    {
         // access fields here
         pSample->IntField = 1;
         pSample->szCharField[0]  = 0;
    }  
}


0
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 12367255
Pointers cannot be used for inter-process communications. Pointer passed to another process is invalid in destination process address space. Your data may be passed in WPARAM and LPARAM (both are 32-bits integers) directly.

int - between four to six digits. May be casted directly to WPARAM or LPARAM.
string - between two to three characters. May be packed to 3 bytes of WPARAM or LPARAM.

Avoid using SendMessage, use PostMessage whenever it is possible. SendMessage is synchronous and doesn't return until receiver handles this message. If receiver application hangs, sender hangs as well. Use SendMessage only if you need to know return code.

You need to think also about getting list of destination applications to post message to them. The simplest way is using HWND_BROADCAST parameter of PostMessage function.
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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 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