Extern Object
Description
Enables you to declare calls to external procedures from an external dynamic-link library (DLL).
Methods
Declare | Declares references to external procedures in a dynamic-link library (DLL). |
Any declared method (see Declare method for more details).
Declare Method
Description
Declares references to external procedures in a dynamic-link library (DLL).
After you use the Declare method for a method, you can use the Extern object to call the declared method.
Syntax
Extern.Declare(RetType, MethodName, LibName, Alias, [ArgType(s)])
Argument | Type | Description |
---|---|---|
RetType | String | Data type of the value returned by the method. For available data types, see Extern.Declare Data Types. Note: String value types (micString and micWideString) are not supported as return values. To return a string value, use a string out argument in the called procedure. In the Extern.Declare statement, use micVoid for the RetType argument and micByRef + micString (or other relevant string type) for the ArgType argument. For a complete example, see Returning a String Value Using an Extern.Declare Statement. |
MethodName | String | Any valid procedure name. |
LibName | String | Name of the DLL or code resource that contains the declared procedure. |
Alias | String | Name of the procedure in the DLL or code resource. Note:
|
ArgType(s) | String | A list of data types representing the data types of the arguments that are passed to the procedure when it is called. For available data types, see Extern.Declare Data Types. Note: For out arguments, use the micByRef flag. |
The following example uses the Extern.Declare and Extern.<declared method> methods to change the title of the Notepad window.
'Declare FindWindow method
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("Notepad", vbNullString)
if hwnd = 0 then
MsgBox "Notepad window not found"
end if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "kuku")
The following example retrieves information from an external INI file using GetPrivateProfileString, and uses it in the test. Note the use of the micByRef flag to indicate the out argument.
Extern.Declare micInteger,"GetPrivateProfileStringA", "kernel32.dll","GetPrivateProfileStringA", micString, micString, micString, micString+micByRef, micInteger, micString
Dim key, i, key2
key = String(32, "-")
i = Extern.GetPrivateProfileStringA("WREnv","addons","xxx", key, 32, "wrun.ini")
key2 = Left(key,i)
msgbox key & ";" & key2 & ";" & CStr(i)
The following example checks when the cursor is displayed as an hour glass.
extern.Declare micLong,"GetForegroundWindow","user32.dll","GetForegroundWindow"
extern.Declare micLong,"AttachThreadInput","user32.dll","AttachThreadInput",micLong,
micLong,micLong
extern.Declare micLong,"GetWindowThreadProcessId","user32.dll",
"GetWindowThreadProcessId",micLong,micLong
extern.Declare micLong,"GetCurrentThreadId","kernel32.dll","GetCurrentThreadId"
extern.Declare micLong,"GetCursor","user32.dll","GetCursor"
function get_cursor()
hwnd = extern.GetForegroundWindow()
pid = extern.GetWindowThreadProcessId(hWnd, NULL)
thread_id=extern.GetCurrentThreadId()
extern.AttachThreadInput pid,thread_id,True
get_cursor=extern.GetCursor()
extern.AttachThreadInput pid,thread_id,False
end function
Msgbox get_cursor()
See also:
- Crypt Object
- DataTable Object
- Description Object
- DeviceReplay Object
- DotNetFactory Object
- DTParameter Object
- DTSheet Object
- Environment Object
- Extern Object
- Parameter Object
- JSON Object
- JsonUtil Object
- MercuryTimers Object (Collection)
- MercuryTimer Object
- NV Object
- OptionalStep Object
- ParallelUtil Object
- LocalParameter Object
- PasswordUtil Object
- PathFinder Object
- PDFUtil Object
- Properties Object (Collection)
- QCUtil Object
- RandomNumber Object
- Recovery Object
- Remote Connection Object
- Reporter Object
- RepositoriesCollection Object
- Repository Object
- Services Object
- Setting Object
- SystemMonitor Object
- TestArgs Object
- TextUtil Object
- UIAutomation Object
- VisualRelation Object
- VisualRelations Object
- VisualRelationsCollection Object
- WebUtil Object
- XMLUtil Object