I am using Dynawrap to get text from a dialog box, and when I try to grab anything of the class "Static", I receive the following error: "Run-time error '-2147417848 (80010108)': Automation error. The object invoked has disconnected from its clients." I wrote the code for VBS but copied the code into a VBA module to debug and step through the code. It will get the text from a button in the dialog box and from the title of the dialog box, but not the text in the box. If someone could help, I would appreciate it! The following code is what I'm using:
[blue]<snip>
dim sWindowTitle
hwnd = clng(&H02000534) [!]'handle to the desired window[/!]
dasLength = GetWindowTextLength(hwnd)
sWindowTitle = String(dasLength + 1, vbnullchar)[!]'to create the necessary buffer space[/!]
charnum = GetWindowText(hwnd, sWindowTitle, dasLength + 1)
MsgBox (sWindowTitle)
Function GetWindowText(hwnd, txt, char)
Set oDW = Nothing [!]'remove previous instances[/!]
Set oDW = CreateObject("DynamicWrapper") [!]'create new instance[/!]
oDW.Register "USER32.DLL", "GetWindowTextA", "i=lrl", "f=s", "r=l" [!]'register the dll for use[/!]
GetWindowText = oDW.GetWindowTextA(hwnd, txt, char)
End Function
Function GetWindowTextLength(hwnd)
Set oDW = Nothing
Set oDW = CreateObject("DynamicWrapper")
oDW.Register "USER32.DLL", "GetWindowTextLengthA", "i=h", "f=s", "r=l"
GetWindowTextLength = oDW.GetWindowTextLengthA(hwnd)
End Function
</snip>[/blue]
[blue]<snip>
dim sWindowTitle
hwnd = clng(&H02000534) [!]'handle to the desired window[/!]
dasLength = GetWindowTextLength(hwnd)
sWindowTitle = String(dasLength + 1, vbnullchar)[!]'to create the necessary buffer space[/!]
charnum = GetWindowText(hwnd, sWindowTitle, dasLength + 1)
MsgBox (sWindowTitle)
Function GetWindowText(hwnd, txt, char)
Set oDW = Nothing [!]'remove previous instances[/!]
Set oDW = CreateObject("DynamicWrapper") [!]'create new instance[/!]
oDW.Register "USER32.DLL", "GetWindowTextA", "i=lrl", "f=s", "r=l" [!]'register the dll for use[/!]
GetWindowText = oDW.GetWindowTextA(hwnd, txt, char)
End Function
Function GetWindowTextLength(hwnd)
Set oDW = Nothing
Set oDW = CreateObject("DynamicWrapper")
oDW.Register "USER32.DLL", "GetWindowTextLengthA", "i=h", "f=s", "r=l"
GetWindowTextLength = oDW.GetWindowTextLengthA(hwnd)
End Function
</snip>[/blue]