473,668 Members | 2,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use SendMessage in VB.NET

This is what need to do
Win32.User.Send Message(Win32.U ser.HWND_BROADC AST,
Win32.User.WM_W ININICHANGE, 0, "windows")

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

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

[DllImport("user 32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, [MarshalAs(Unman agedType.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(hwn d 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 18885
* " active" <ac****@REMOV Ea-znet.com> scripsit:
This is what need to do
Win32.User.Send Message(Win32.U ser.HWND_BROADC AST,
Win32.User.WM_W ININICHANGE, 0, "windows")

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

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

[DllImport("user 32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, [MarshalAs(Unman agedType.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 'MarshalAsAttri bute' does?
'Public Shared Function SendMessage(hwn d 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.Send Message(Win32.U ser.HWND_BROADC AST,
Win32.User.WM_W ININICHANGE, 0, "windows")

Tried both of these in Win32.User. (one at a time)
[DllImport("user 32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, String s);

[DllImport("user 32")] public static extern int SendMessage(int hwnd, int
wMsg, int wParam, [MarshalAs(Unman agedType.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 'MarshalAsAttri bute' does?

Yes - not sure I have much insight and may be misunderstandin g.
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(hwn d 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
19401
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 = Win32API.SendMessage(hWndYesButton,Win32API.BM_SETSTATE,0,null); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,"11"); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,null); response =...
3
10157
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" as a data type but it appears to fall short of using pointer types. Any help or insight would be greatly appreciated. Thank You
0
1711
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
5329
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 at it and let me know what I need to change. I have tried changing the "hwnd" type into intptr's but there seem to be other problems too, like it won't allow "lParam As Any" to be declared.
18
6557
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(). Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
3
5085
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 the purpose of receiving and handeling user defined messages:
4
2128
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 by protecting it in a critical section, or the SendMessage api itself handles this kind of situation where a lot of threads in the same process r calling it. Regards,
22
9238
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. I'm sure the problem is the way i'm using the sendmessage API, the return string and the lParam return 0....is anybody have a clue? any sendmessage api expert here? public static extern Int32 FindWindow(String lpClassName,String
1
13407
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 Attachmate. It is a mainframe terminal. Here is the issue and strange part of it. It is accepting sendmessage when I use the WM_KEYDOWN/UP commands. However, when I use WM_SETTEXT to send my string it is not imputing the string to the session...
5
5232
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 marshaling the struct to be able to use it in sendmessage... Here is an example LM_GETITEM: http://msdn.microsoft.com/en-us/library/bb760720(VS.85).aspx
0
8459
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8371
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8889
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
7391
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 project—planning, coding, testing, and deployment—without 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
6206
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
5677
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();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
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.