API SendMessage WM_GETTEXT??

  • Thread starter Thread starter MyNuS
  • Start date Start date
M

MyNuS

Guest
Ive been having problems with a module that I am working on. I can get my program to send a wm_gettext message to an other aplication, but it wont send the string to the buffer. The function returns the appropriate lenght of string copied, and every other message that i try to send with sendmessage works. Thanks for your help.
--------------------------CODE------------------------
Imports System.Runtime.InteropServices
Public Const WM_GETTEXT = &HD

<DllImport("user32.dll")> _
Public Function SendMessage(ByVal hWnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
End Function

Function getWinText() As String
Dim n As Integer, s As String, q As Integer
s$ = Space$(255)
n = SendMessage(3080978, WM_GETTEXTLENGTH, 0, 0)
q = SendMessage(3080978, WM_GETTEXT, 254, s$)
getImSn = s$
End Function
 
Let me offer you this example:

Code:
Public Declare Ansi Function GetWindowText Lib "User32.dll" Alias "GetWindowTextA" ( _
    ByVal hwnd As Integer, _
    ByVal lpString As StringBuilder, _
    ByVal nMaxCount As Integer) As Integer

Dim s As New StringBuilder(256)
Win32API.GetWindowText(hwnd, s, s.Capacity)

MessageBox.Show(s.ToString(), Application.ProductName)

Also, for a brief overview of using buffers, take a look at this article:
http://www.elitevb.com/content/01,0075,01/05.aspx
 
Thanks for the help! I got it now. Just in case anyone else reads this for reference in vb.net you need to use:
Imports System.Text to use the stringbuilder.
Thanks again.
 
Last edited by a moderator:
Back
Top