alt66
12 years agoNew Contributor
WinAPI32
I have been trying to call the Windows API function:
But the first issue is it receives / returns a pointer (reference) to a structure (struct) containing two long (I4) variables so when I tried this way, using Win32Api plug in, but I had no way in vbscript to declare such structure:
hwnd = UIObject.handle
dc = Win32Api.GetDC(hwnd)
ret = Win32Api.GetTextExtentPoint32(dc, UIObject.Text , Len(UIObject.Text), TextSize)
Call Win32Api.ReleaseDC(hwnd,dc)
In this case if TextSize is unidefined, it stays undefined after the call, and there is no error, if it points to a class with two variants it sends an error
Then I tried the more longer and cumbersome method to call any function in any dll, it allows to create the structures and make the call(s) after a long list of definition and setup steps:
' Calls definitions
Set uddl = DLL.DefineDLL("USER32")
Call uddl.DefineProc("GetDC", vt_i4, vt_i4)
Call uddl.DefineProc("ReleaseDC", vt_i4, vt_i4, vt_i4)
Set ULib = DLL.Load("USER32")
Set ddll = DLL.DefineDLL("GDI32")
dsize = DLL.DefineType("SIZE", vt_i4, "X", vt_i4, "Y")
Call ddll.DefineProc("GetTextExtentPoint32A", vt_i4, vt_lpstr, vt_int, dsize, vt_b1)
Call ddll.DefineAlias("GetTextExtentPoint32", "GetTextExtentPoint32A")
Set Lib = DLL.Load("GDI32")
' Parameters setup
hwnd = UIObject.handle
dc = ULib.GetDC(hwnd)
Set lpstr = DLL.New("LPSTR", 256)
lpstr.Text = UIObject.Text
ln = Len(lpstr.Text)
Set TextSize = DLL.New("SIZE")
' Actual call
Call Lib.GetTextExtentPoint32(dc, lpstr , ln, TextSize)
Call ULib.ReleaseDC(hwnd, dc)
And the result of all of this is a cryptic message when the actual call is made:
An exception occurred: 0xC0000005; class: ; description: ''
I am using the latest Test Complete 9 version (downloaded as free trial last week) and I am still wondering what is wrong with the code. Does any body knows?
GetTextExtentPoint32
But the first issue is it receives / returns a pointer (reference) to a structure (struct) containing two long (I4) variables so when I tried this way, using Win32Api plug in, but I had no way in vbscript to declare such structure:
hwnd = UIObject.handle
dc = Win32Api.GetDC(hwnd)
ret = Win32Api.GetTextExtentPoint32(dc, UIObject.Text , Len(UIObject.Text), TextSize)
Call Win32Api.ReleaseDC(hwnd,dc)
In this case if TextSize is unidefined, it stays undefined after the call, and there is no error, if it points to a class with two variants it sends an error
Then I tried the more longer and cumbersome method to call any function in any dll, it allows to create the structures and make the call(s) after a long list of definition and setup steps:
' Calls definitions
Set uddl = DLL.DefineDLL("USER32")
Call uddl.DefineProc("GetDC", vt_i4, vt_i4)
Call uddl.DefineProc("ReleaseDC", vt_i4, vt_i4, vt_i4)
Set ULib = DLL.Load("USER32")
Set ddll = DLL.DefineDLL("GDI32")
dsize = DLL.DefineType("SIZE", vt_i4, "X", vt_i4, "Y")
Call ddll.DefineProc("GetTextExtentPoint32A", vt_i4, vt_lpstr, vt_int, dsize, vt_b1)
Call ddll.DefineAlias("GetTextExtentPoint32", "GetTextExtentPoint32A")
Set Lib = DLL.Load("GDI32")
' Parameters setup
hwnd = UIObject.handle
dc = ULib.GetDC(hwnd)
Set lpstr = DLL.New("LPSTR", 256)
lpstr.Text = UIObject.Text
ln = Len(lpstr.Text)
Set TextSize = DLL.New("SIZE")
' Actual call
Call Lib.GetTextExtentPoint32(dc, lpstr , ln, TextSize)
Call ULib.ReleaseDC(hwnd, dc)
And the result of all of this is a cryptic message when the actual call is made:
An exception occurred: 0xC0000005; class: ; description: ''
I am using the latest Test Complete 9 version (downloaded as free trial last week) and I am still wondering what is wrong with the code. Does any body knows?