diff --git a/PInvoke/User32/WinUser.Message.cs b/PInvoke/User32/WinUser.Message.cs index 4de894f2..6560b54b 100644 --- a/PInvoke/User32/WinUser.Message.cs +++ b/PInvoke/User32/WinUser.Message.cs @@ -2065,7 +2065,7 @@ namespace Vanara.PInvoke [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("Winuser.h", MSDNShortId = "ms644950")] [System.Security.SecurityCritical] - public static extern IntPtr SendMessage(HWND hWnd, uint msg, IntPtr wParam = default, IntPtr lParam = default); + public static extern IntPtr SendMessage(HWND hWnd, uint msg, [In] IntPtr wParam = default, [In] IntPtr lParam = default); /// /// @@ -2099,7 +2099,7 @@ namespace Vanara.PInvoke [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("Winuser.h", MSDNShortId = "ms644950")] [System.Security.SecurityCritical] - public static extern IntPtr SendMessage(HWND hWnd, uint msg, IntPtr wParam, string lParam); + public static extern IntPtr SendMessage(HWND hWnd, uint msg, [In] IntPtr wParam, string lParam); /// /// @@ -2135,6 +2135,40 @@ namespace Vanara.PInvoke [System.Security.SecurityCritical] public static extern IntPtr SendMessage(HWND hWnd, uint msg, ref int wParam, [In, Out] StringBuilder lParam); + /// + /// + /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified + /// window and does not return until the window procedure has processed the message. + /// + /// + /// To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a + /// message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function. + /// + /// + /// + /// + /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST + /// ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, + /// overlapped windows, and pop-up windows; but the message is not sent to child windows. + /// + /// + /// Message sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of + /// lesser or equal integrity level. + /// + /// + /// + /// The message to be sent. + /// For lists of the system-provided messages, see System-Defined Messages. + /// + /// Additional message-specific information. + /// Additional message-specific information. + /// The return value specifies the result of the message processing; it depends on the message sent. + // LRESULT WINAPI SendMessage( _In_ HWND hWnd, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam); https://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx + [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("Winuser.h", MSDNShortId = "ms644950")] + [System.Security.SecurityCritical] + public static extern IntPtr SendMessage(HWND hWnd, uint msg, [In] IntPtr wParam, [In, Out] StringBuilder lParam); + /// /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window /// and does not return until the window procedure has processed the message. diff --git a/UnitTests/PInvoke/User32/User32Tests.cs b/UnitTests/PInvoke/User32/User32Tests.cs index 478bd40b..51fd0a2a 100644 --- a/UnitTests/PInvoke/User32/User32Tests.cs +++ b/UnitTests/PInvoke/User32/User32Tests.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Runtime.InteropServices; +using System.Text; using Vanara.InteropServices; using static Vanara.PInvoke.User32; @@ -102,10 +103,13 @@ namespace Vanara.PInvoke.Tests [Test()] public void SendMessageTest1() { - throw new NotImplementedException(); + var length = 256; + var sb = new StringBuilder(length); + Assert.That(SendMessage(FindWindow("Progman", null), (uint)WindowMessage.WM_GETTEXT, (IntPtr)sb.Capacity, sb).ToInt32(), Is.GreaterThanOrEqualTo(1)); + TestContext.WriteLine(sb); } - [Test()] + [Test()] public void SendMessageTest2() { throw new NotImplementedException();