473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PostMessage/PeekMessage and interop

Hi

I'm using some of the definitions I found pinvoke.net for PostMessage and
PeekMessage as follows

[return: MarshalAs(Unman agedType.Bool)]
[DllImport("user 32.dll", SetLastError = true)]
public static extern bool PostMessage(
HandleRef hWnd,// handle to destination window
UInt32 Msg, // message
IntPtr wParam, // first message parameter
IntPtr lParam // second message parameter
);

[StructLayout(La youtKind.Sequen tial)]
public struct Message
{
public IntPtr handle;
public uint msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing. Point p;
}
[DllImport("user 32.dll")]
[return: MarshalAs(Unman agedType.Bool)]
public static extern bool PeekMessage(
out Message lpMsg,
HandleRef hWnd,// handle to destination window
uint wMsgFilterMin,
uint wMsgFilterMax,
uint wRemoveMsg
);

WM_USER = 0x0400,
public const int WM_EnteringGym = (int)WinService s.WindowsMessag es.WM_USER +
11;

I post a message as follows:

PostMessage(new HandleRef(null, _MainWindowHand le),
UserMessages.WM _EnteringGym, 1);

I peek for the message as follows:

Message msg;
PeekMessage(out msg, new HandleRef(null, this.Handle),
UserMessages.WM _EnteringGym, UserMessages.WM _EnteringGym, 1);

When it arrives, and I check msg, WParam is 0x118 and LParam is 0x00
Where am i going wrong please? Why isnt WParam 0x01 ?
May 9 '07 #1
1 8948
I have to ask why you are using this mechanism? There are many other
notification mechanisms in the framework other than this which are much
cleaner.

If I had to guess, I would say that you are doing work on another thread
and trying to notify the main window when some unit of work is done. In
this case, you should call the Invoke method on the main window, passing a
delegate to be executed on the thread that created the UI.

The only reason I can see to use this kind of code would be if you have
to send a message to another window in a different process which was
developed using unmanaged code. However, I doubt that is the case because
of your declaration of PeekMessage, which indicates you have managed code
looking for the message.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"SeeSharp Bint" <Se******@nospa m.comwrote in message
news:uW******** ******@TK2MSFTN GP06.phx.gbl...
Hi

I'm using some of the definitions I found pinvoke.net for PostMessage and
PeekMessage as follows

[return: MarshalAs(Unman agedType.Bool)]
[DllImport("user 32.dll", SetLastError = true)]
public static extern bool PostMessage(
HandleRef hWnd,// handle to destination window
UInt32 Msg, // message
IntPtr wParam, // first message parameter
IntPtr lParam // second message parameter
);

[StructLayout(La youtKind.Sequen tial)]
public struct Message
{
public IntPtr handle;
public uint msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing. Point p;
}
[DllImport("user 32.dll")]
[return: MarshalAs(Unman agedType.Bool)]
public static extern bool PeekMessage(
out Message lpMsg,
HandleRef hWnd,// handle to destination window
uint wMsgFilterMin,
uint wMsgFilterMax,
uint wRemoveMsg
);

WM_USER = 0x0400,
public const int WM_EnteringGym = (int)WinService s.WindowsMessag es.WM_USER
+ 11;

I post a message as follows:

PostMessage(new HandleRef(null, _MainWindowHand le),
UserMessages.WM _EnteringGym, 1);

I peek for the message as follows:

Message msg;
PeekMessage(out msg, new HandleRef(null, this.Handle),
UserMessages.WM _EnteringGym, UserMessages.WM _EnteringGym, 1);

When it arrives, and I check msg, WParam is 0x118 and LParam is 0x00
Where am i going wrong please? Why isnt WParam 0x01 ?

May 9 '07 #2

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

Similar topics

15
8437
by: James | last post by:
In my code I have a problem in abtaining a windows handle. I do not know the namespace to obtain the windows hanle. here is the code. using System; using System.Collections; using System.Windows.Forms; using System.Runtime.InteropServices; namespace mynamespace
2
626
by: Jeff | last post by:
What is the .Net Framework equivalent of the Windows API function PeekMessage? Or any other method that will do the same thing. I simply need to check to see if there are messages waiting to be processed. Thanks!
12
7178
by: Wilfried Mestdagh | last post by:
Hi, Using P/Invoke I use PostMessage to send a message from one thread to another. I'm pretty sure this has already worked in dotnet. but I've upgraded version 2 few day ago. Now I have an illegal cross thread operation if posting a message. Is this a bug introduced in latest version of dotnet ? It is very legal to use postmessage ...
17
7047
by: Bonj | last post by:
Is PostQuitMessage(?) different to PostMessage(hWnd, WM_QUIT, ... ) ? I've got a window in a DLL (the same one experiencing the issue below, "return value of WM_QUIT") in which PostMessage(hWnd, WM_QUIT, ... ) works, but PostQuitMessage doesn't. I would assume this to be the case as PostQuitMessage can't possibly know the hWnd I'm wanting...
6
4757
by: SM | last post by:
Hello group, i'm converting a VB6 application for .NET Framework. The application depends on a DLL written in standard C. The C DLL code creates an invisible window with CreateWindow() with the WndProc function located into the VB.NET code. Until the code was VB6/C code, they was OK. Now the VB WndProc receives the startup message...
2
2614
by: Lenster | last post by:
When using PostMessage to post myself a message, the msg and wparam parameters somehow get swapped over. They are in the correct order when calling PostMessage but by the time wndproc handles the message msg is now in the wparam position and msg is set to 0 (NULL message). Does anyone know why this behaviour is occurring ? I've included a...
3
5064
by: Max M. Power | last post by:
When I use the SendMessage API I can sucessfully send and receive a user defined message. When I use the PostMessage API I can NOT sucessfully send and receive the same user defined message. I've got a C# class library project with two classes: Class 1 is derives from : System.Windows.Forms.Form and overrides the base WndProc method for...
3
9451
by: knikkix | last post by:
Hi, I created a form in VB.Net with only one button. This is the code in button click event Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click AppGlobals.SetHandles(Me.Handle.ToInt64()) Call OpenModel() End Sub
10
2564
by: Sergei | last post by:
Can anyone explain why PostMessage to a Windows Form is considered unsafe and raises InvalidOperationException? I can get rid of that setting CheckForIllegalCrossThreadCalls to false and everything works just fine. Still I feel somewhat uncomfortable. Sergei
0
7697
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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. ...
0
8120
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...
0
5219
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...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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...

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.