By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 835 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

How to use SendMessage in VB.NET

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* " active" <ac****@REMOVEa-znet.com> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
>> 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
'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
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.