Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables with PostMessage

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
I am trying to pass a double variable to a function in my main thread by using PostMessage.

My code is as follows:

AfxGetMainWnd()->PostMessage(MY_WM_MESSAGE_FREQUENCY,m_RecordingProgrammeFrequency,0);

This works fine an executes the following function:

LRESULT COneDlg::OnUpdateFrequency(WPARAM RecordFrequency, LPARAM lParam)

{
m_pWinTV->SetFrequency(RecordFrequency);
return (LRESULT) 1;
}

The problem i am having is that the computer cuts off my double.

For example: 95.95 becomes 95

My first thoughts are that i should pass a pointer to the double instead but am having problems doing this too.

Does anyone have any suggestions?

Mark.
 
Use the LPARAM argument of PostMessage rather than the WPARAM, it's a larger storage type than the WPARAM and the double type will fit.

-pete

 
Dear All,

I have tried the suggestion from pete but the LPARAM is still a long integer and won't take my double (floating point number)
 
The problem is the implicit conversion from double to WPARAM or LPARAM (they are both 32-bit numbers).

You could try this,

double d = 95.95
long *pl = (long*)&d;
wnd.SendMessage(pl[0],pl[1]);

Note that this gets very messy and for sure isn't portable.
 
>> Use the LPARAM argument of PostMessage rather than the
>> WPARAM, it's a larger storage type than the WPARAM and
>> the double type will fit.

NO, that will not work! double is a "complex" type and therefore cannot simply be cast to simple types!

What BONEHEAD told you that? oh... right... it was me...

LOL
Seriously though, i am sorry for wasting your time with a hasty response that i didn't even spend time thinking about. I will try to do better in the future.

-pete


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top