473,766 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing A Float In WParam or LParam of Windows Message

I have an application that sends messages to other applications through
PostMessage(HWN D_BROADCAST, MY_MESSAGE_ID, wparam_float, lparam_float);
in C (and this works... I can typecast and built byte arrays with
whatever I want in C and extract them at the other end just fine).

I am now needing to interface with C# and find I cannot do this in an
easy way (at least for me). When I try something like:

Single sValue= (Single) m.LParam;

in my OnNotifyMessage override, I get a float (Single) but of the large,
"integer" value it things LParam must be (but it's not, it's a 4-byte
floating point value).

Any thoughts on what to do to make C# "typecast" this to a Single, properly?

Thanks,
Dave
Apr 16 '07 #1
7 4008
Hi Dave,

I am not sure I understand your problem completely. Can you help to explain
the following statement clearer?
"in my OnNotifyMessage override, I get a float (Single) but of the large,
"integer" value it things LParam must be (but it's not, it's a 4-byte
floating point value)."

Based on my experience, m.LParam is of type "IntPtr", however, it should be
no problem to convert it into Single if you are sure that this message's
lParam is actually float type.

I will wait for your further clarify, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 16 '07 #2
Jeffrey Tan[MSFT] wrote:
Hi Dave,

I am not sure I understand your problem completely. Can you help to explain
the following statement clearer?
"in my OnNotifyMessage override, I get a float (Single) but of the large,
"integer" value it things LParam must be (but it's not, it's a 4-byte
floating point value)."

Based on my experience, m.LParam is of type "IntPtr", however, it should be
no problem to convert it into Single if you are sure that this message's
lParam is actually float type.
What you say may be correct (I cannot verify, as I"M not in front of the C#
system right now). But, yes, I do wish to treat this IntPtr as a Single (float)
as that is what it is (really, it is!). I just have not found a way to do it (I
am a new C# programmer, does it show?)

Thanks!
Dave
Apr 16 '07 #3
Hi Dave,

Thanks for your feedback.

System.IntPtr is also a value type which is used to represent a pointer or
a handle. On x86 system, the handle and pointer is of length 4 bytes, so
the System.IntPtr is also 4 bytes. Since System.Single type is also a value
type with 32bit(4 bytes) length, you can convert m.LParam to "Single"
directly without any problem.

I have copied your code below into the VS2005 C# IDE, it compiles without
any problem:
Single sValue= (Single) m.LParam;

Anyway, if you need any further help, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Apr 17 '07 #4
Jeffrey Tan[MSFT] wrote:
Hi Dave,

Thanks for your feedback.

System.IntPtr is also a value type which is used to represent a pointer or
a handle. On x86 system, the handle and pointer is of length 4 bytes, so
the System.IntPtr is also 4 bytes. Since System.Single type is also a value
type with 32bit(4 bytes) length, you can convert m.LParam to "Single"
directly without any problem.

I have copied your code below into the VS2005 C# IDE, it compiles without
any problem:
Single sValue= (Single) m.LParam;
OK, I'm obviously not being clear. What you are showing takes whatever integer
value is in m.LParam and represents that as a float. For example, if m.LParam is
0xc269b440 (-1033259968)then sValue = -1.033259968E+9. This is NOT correct.
The value in m.LParam is 5.6379 when read as an actual floating point value.
This is what m.LParam is. It's not an integer at all.

In C, for example, I do something like

float *mfp = (float *) &LParam;
float myfloat = *mfp;

Now the final result is in myfloat and is the floating point value that was
passed as opposed to the floating point representation of the integer in LParam.

This is what I cannot do in C#. Well, I guess I could do the same thing with
unmanaged code and pointers, but I was hoping for a better way. And I've
actually had no luck getting unmanaged code to work in this way, either, which
is why I assumed there must be a better way.

Any new thoughts?

Thanks,
Dave
Apr 17 '07 #5
On Tue, 17 Apr 2007 06:36:05 -0700, dzar <dz**@nospam.no spamwrote:
[...]
This is what I cannot do in C#. Well, I guess I could do the same thing
with unmanaged code and pointers, but I was hoping for a better way.
And I've actually had no luck getting unmanaged code to work in this
way, either, which is why I assumed there must be a better way.
I'm not sure why you can't get it to work using unsafe code. I also am
not sure there's not a better way, but you should be able to do what you
want using the BitConverter class.

Pete
Apr 17 '07 #6
Peter Duniho wrote:
On Tue, 17 Apr 2007 06:36:05 -0700, dzar <dz**@nospam.no spamwrote:
>[...]
This is what I cannot do in C#. Well, I guess I could do the same
thing with unmanaged code and pointers, but I was hoping for a better
way. And I've actually had no luck getting unmanaged code to work in
this way, either, which is why I assumed there must be a better way.

I'm not sure why you can't get it to work using unsafe code. I also am
not sure there's not a better way, but you should be able to do what you
want using the BitConverter class.
Perfect! Thank you for the pointer to the BitConverter class. It does exactly
what I want. I'm new and finding my way though all the classes is quite a chore!
Glad this is as easy as it should be.

Regards,
Dave
Apr 17 '07 #7
Hi Dave,

Sorry for misunderstandin g your point.

Oh, I think I understand your meaning now.

In the message sending side, you have converted the float bytes layout and
re-interpret it as DWORD. So in the .Net managed code receiving side, you
need to get the pure bytes layout of the *int* and re-interpret it as float
type. So, the code snippet below demonstrated your logic:

//Message Sending side, bytes convetion
float f = (float)3.141592 6;
Byte [] bytes=BitConver ter.GetBytes(f) ;
IntPtr ip = (IntPtr)BitConv erter.ToUInt32( bytes, 0);

//Message Receving side
Single new_f=BitConver ter.ToSingle(Bi tConverter.GetB ytes((uint)ip), 0);

I think this code snippet should meet your need. If not, please feel free
to let me know. Thanks.

Also, thank Peter for his sharing.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Apr 18 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1340
by: Sreejith P S | last post by:
Hi I am doing migration of MFC code from CV++.6 to VC++.NET . I found a difference between handing MFC “ON_COMMAND” message function prototype In VC++ .6 the function prototype is BOOL FUN(WPARAM, LPARAM). But in VC++.NET the function prototype is void FUN( ) My Question - How will I get wparam inside VC++.NET ? I am giving the function which is compiled in VC++.6
3
2903
by: dbru | last post by:
I need to pass an address of a Managed float array to a DLL. The following doesn't seem to work extern static float GetXXX( StringBuilder HWND, long nWhat, ref float lparam );
3
1358
by: Just Me | last post by:
Public Declare Auto Function SendMessageRef Lib "user32.dll" Alias "SendMessage" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByRef lParam As PARAFORMAT2) As Integer PARAFORMAT2 is a structure that SendMessage will return stuff in.
4
7919
by: crafuse | last post by:
Hello, I've overridden the WndProc function in my form to hand some special behavior. Specifically, I look for the WM_NCMOUSEMOVE event to tell me when the user is trying to move the window by draggin the title bar. However, I am having trouble extracting the POINT structure that is supposed to come with the message. For example: Structure POINTS Public x As Short
2
2596
by: Carl Heller | last post by:
Working in VS2003, .Net 1.1 I'm working on a project where I compare data between two databases. This is a lengthy process, and very data intensive, so I decided to create a class, and thread out the work. The order of work is as follows: 1. Retrieve the data from primary data source 2. Update UI with retrieved data - this is accomplished by passing a dataset as an event parameter
2
4247
by: william.w.oneill | last post by:
I have an application that takes a few command line parameters. As recommended by others in this group, I'm using a named mutex to ensure that only one instance of the application is running. My question is how to elegantly pass a command line parameter from Instance_B to Instance_A where Instance_A was running prior to Instance_B. For example, the user can launch the program by passing a file name as a command line argument. The program...
0
1100
by: Matthew Page | last post by:
I am trying to pass a message to a userform in VBA. I will include the code of what I have so far below. The problem I am having is that I don't know what I need to send in order to get the text I want to appear in the textfield that I want it to appear in. Here is the code... Private Const WM_SETTEXT As Long = &HC Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal...
14
12649
by: Kerem Gmrkc | last post by:
Hi, i want to emulate a (synchronous) BroadCastSystemMessage with EnumWindows and SendMessage. I dont want to use the BroadcastSystemMessage because it needs the SE_TCB_NAME Privilege (you dont have this in normal). So i decided to use the EnumWindows with SendMessage. What i try here is to pass a WM_USER+1111 with LParam and WParam, pointing to strings. But when i try to get the strings at the other end with Marshal.PtrToStringAnsi,
0
1126
by: Anand Ganesh | last post by:
Hello Everybody, I want to give a Windows 32 API SendMessage command to Windows Media Player and Pause it or Play it. The shortcut command is Control-P. What is the hexadecimal value I should use and how can I find this? I found out WM_KEYDOWN is 0x100 and WM_KEYUP is 0x101. Hope this right.
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.