473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to use SendMessage in VB.NET

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
2 18854
* " 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
>> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response =...
3
by: JSK | last post by:
Hi, As any one worked in VB.NET and made use of Sendmessage API? The Issue I am running into is how to pass pointers of Data Structures (UDT) to the SendMessage. I starting looking at "IntPrt"...
0
by: SamSpade | last post by:
In my C# library I have many SendMessages like the following: public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref PARAFORMAT2 pf2); I use this one like this:
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
18
by: Lars Netzel | last post by:
Hello! Thanx to this newgroup I have finally, with the help of you guys, gotten this to work halfway.. but the final action is still not working, clicking the "Button2" thru SendMessage(). ...
3
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. ...
4
by: Abubakar | last post by:
Hi, My application has a lot of threads which at some point call SendMessage api passing it the handle of the gui window. The calls r a lot. My question is that should I call the SendMessage api...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
1
by: Necromis | last post by:
Ok, I have gotten my head around things better regarding SendMessage and FindWindow functions. However, I am running into an issue with my code still. The program I am working with is EXTRA! by...
5
by: michelqa | last post by:
Hi, I need to call a lot of different native SendMessage to retreive informations from non managed application. Some win32 messages use struct pointer for lparam....how to create and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.