How to use SendMessage in VB.NET

A

active

This is what need to do
Win32.User.SendMessage(Win32.User.HWND_BROADCAST,
Win32.User.WM_WININICHANGE, 0, "windows")

Tried both of these in Win32.User. (one at a time)

[DllImport("user32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, String s);

[DllImport("user32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, [MarshalAs(UnmanagedType.LPStr)]String s);

Are these really different or does the first do the same as the second?





The compile error I get is

'Public Shared Function SendMessage(hwnd As Integer, wMsg As Integer,
wParam As Integer, s As String) As Integer': Reference to a non-shared
member requires an object reference.


Any idea how to do it correctly?





Cal
 
H

Herfried K. Wagner [MVP]

* " active said:
This is what need to do
Win32.User.SendMessage(Win32.User.HWND_BROADCAST,
Win32.User.WM_WININICHANGE, 0, "windows")

Tried both of these in Win32.User. (one at a time)

[DllImport("user32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, String s);

[DllImport("user32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, [MarshalAs(UnmanagedType.LPStr)]String s);

Are these really different or does the first do the same as the second?

Did you have a look at the documentation what 'MarshalAsAttribute' does?
'Public Shared Function SendMessage(hwnd As Integer, wMsg As Integer,
wParam As Integer, s As String) As Integer': Reference to a non-shared
member requires an object reference.

\\\
Public Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal s As String _
) As Int32
///
 
A

active

This is what need to do
. Win32.User.SendMessage(Win32.User.HWND_BROADCAST,
Win32.User.WM_WININICHANGE, 0, "windows")

Tried both of these in Win32.User. (one at a time)


[DllImport("user32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, String s);

[DllImport("user32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, [MarshalAs(UnmanagedType.LPStr)]String s);

Are these really different or does the first do the same as the second?

Did you have a look at the documentation what 'MarshalAsAttribute' does?
Yes - not sure I have much insight and may be misunderstanding.
But the above attempt is what I got from reading it.

I do know that I don't know what happens with the one that ends with
wParam, String s); I guess some kind of marshalling is taking place there.


This is where I am now: I'm pretty sure the complaint is about the first
argument, HWND_BROADCAST, which without thinking about it I had assumed it
was typed int as are most constants.

It actually defined as follows:

public HWND HWND_BROADCAST

{

get { return (HWND) 0xFFFF; }

}



I'd guess that as soon as I learn to say "Shared" in C# I'll have it
licked.



Thanks for all your help,

Cal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top