|
-
Feb 20th, 2000, 09:37 AM
#1
Thread Starter
Hyperactive Member
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
-
Feb 20th, 2000, 11:54 PM
#2
Hyperactive Member
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).]
-
Feb 21st, 2000, 03:08 AM
#3
Thread Starter
Hyperactive Member
You don't need it. It is already there from the Declare statement.
.., ByVal wParam As Long
and that is not the problem.
-
Feb 21st, 2000, 03:31 AM
#4
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)
-
Feb 21st, 2000, 03:54 AM
#5
Hyperactive Member
Since ByVal is in the Declare statement for every argument, you shouldn't get an Automation error when removing the last ByVal..correct??
-
Feb 21st, 2000, 04:02 AM
#6
Thread Starter
Hyperactive Member
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).]
-
Feb 21st, 2000, 04:03 AM
#7
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.
-
Feb 21st, 2000, 04:08 AM
#8
Thread Starter
Hyperactive Member
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
-
Feb 21st, 2000, 04:15 AM
#9
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.
-
Feb 21st, 2000, 04:18 AM
#10
Thread Starter
Hyperactive Member
Tried that. Doesn't work.
-
Feb 21st, 2000, 11:56 AM
#11
Thread Starter
Hyperactive Member
-
Feb 21st, 2000, 12:07 PM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|