SendMessage Function (Sub in C#)
-
OK, so I'm using PInvoke - doing the following:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
But I'm receiving the following error:Error 2 The modifier 'extern' is not valid for this item
Error 3 Expected class, delegate, enum, interface, or structWhy ??? :confused::confused:
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
where did you find "HandleRef"? that's why the compiler expected class, delegate, enum, interface, etc I think.. try the code below.. I have no idea how to use it because it only return the message ID which I don't know how to process..
[DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
CMIIWMail me at erwin@holyknight.us
-
where did you find "HandleRef"? that's why the compiler expected class, delegate, enum, interface, etc I think.. try the code below.. I have no idea how to use it because it only return the message ID which I don't know how to process..
[DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
CMIIWMail me at erwin@holyknight.us
Where do I place it. At the moment I placed it here (is this correct?
... using System.IO; [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam); namespace WindowsService { ...
Many thanks for the reply Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
OK, so I'm using PInvoke - doing the following:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
But I'm receiving the following error:Error 2 The modifier 'extern' is not valid for this item
Error 3 Expected class, delegate, enum, interface, or structWhy ??? :confused::confused:
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Hi,
Programm3r wrote:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
you have to put these lines inside a class, any class would do (I use LP_user32 for all user32.dll functions). :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi,
Programm3r wrote:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
you have to put these lines inside a class, any class would do (I use LP_user32 for all user32.dll functions). :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
Yep, put it inside a class.. search in microsoft documentation for more info about windows messaging, the message type, and other info.. CMIIW
Mail me at erwin@holyknight.us
-
Hi,
Programm3r wrote:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
you have to put these lines inside a class, any class would do (I use LP_user32 for all user32.dll functions). :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
Ok, I'm trying this ....
class WindowsService : ServiceBase { [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
But I receive this: Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Ok, I'm trying this ....
class WindowsService : ServiceBase { [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
But I receive this: Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Ok, I'm trying this ....
class WindowsService : ServiceBase { [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
But I receive this: Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Visual Studio is kind enough to include the probable fix in the error message. MSDN will tell you which namespace DllImport belongs to. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Ok, I'm trying this ....
class WindowsService : ServiceBase { [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
But I receive this: Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Add this line to your using directives list: using System.Runtime.InteropServices;
#region signature my articles #endregion
-
Thanks :)
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Add this line to your using directives list: using System.Runtime.InteropServices;
#region signature my articles #endregion
Thanks :)
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Hi all, What can I use within C# to replace the function:
LRESULT SendMessage( HWND hWnd, // handle of destination window UINT Msg, // message to send WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );
Many Thanks in advance Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
Is it possible to show a MessageBox from a Service developed in C# ? Many Thanks Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Is it possible to show a MessageBox from a Service developed in C# ? Many Thanks Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
When you say "Service" do you mean that your C# program is running as a Windows Service? That's my assumption here, and yes it's possible. Whether or not it's advisable is another matter. Now when I say "possible" I mean that the code will compile and build, and the .exe can be installed as a Windows Service and run. Often times one of the main reasons to develop a solution to run as a Windows Service is so that it can run even when no user is logged in to the computer. Now if that's the case, and the code finds it way down the path to where the MessageBox is .Show()'n, I don't know what will happen. Maybe nothing. Maybe it's displayed and causes the Service to stop executing until the nonexistent user clicks the unseen "OK" button. Of course you could try it and see what happens. If you do, post your results here so everyone can know, too. Then try to find out if a tree falls in the forest.... ;) BDF