Home > Language Reference > System Functions > External

External

The External function executes the specified function in a DLL and retrieves the return value of the function.

Usage

Used to call DLL functions and therefore an ideal way of extending the WinTask x64 language using custom DLLs or for calling Win32 API functions.

Syntax

var = External(<DLL_name>, <method_name> [, <param1>[, <param2>, ...]])

Parameters

<DLL_name>. string, name of the DLL to perform the function on.

<method_name>. string, name of the DLL function to call.

<param1>, <param2> . optional parameters, type integer or unsigned or string. If <paramx> is an output string, its maximum length is 1023 characters. If you need to use a longer string parameter, use External$.

Return value

var, 32-bit integer or UNSIGNED for a pointer.

Remarks

A WinTask x64 customer has written many scripts using Windows API functions, you can view them at http://strazzere.blogspot.com and search for WinTask x64.

See also

Allocate
External$

Examples

'This example shows the use of the GetWindowsDirectory function to get the name of the directory where Windows is installed.
wdir$=" "
a=External("kernel32","GetWindowsDirectoryA",wdir$,145)
msgbox(wdir$)



'This more complex example gives the name of the computer
Dim compName as unsigned 'Space for the computer name string
Dim bufferLen as unsigned 'Space for the length of the string
'Initialization
compName = Allocate(255)
bufferLen = Allocate(4)
PokeInteger(bufferLen, 255, 4) 'Initialize the length of the buffer
' According to MSDN the second parameter of GetComputerName is a pointer to a dword, not a dword.
'BOOL GetComputerName( LPTSTR lpBuffer, // computer name
' LPDWORD lpnSize // size of name buffer)
ret=External("kernel32.dll", "GetComputerNameA", compName, bufferLen)
name$=PeekString$(compName)
MsgBox(name$)


'This example returns the mouse position on the screen
'It calls the Windows API GetCursorPos
'External, structure, allocate, peekinteger, pokeinteger are used.
'When you call Windows API functions, data is often written in
'structures (memory areas). A structure can contain various data (integer,
'string, etc ...). The only way to access this data is to use the WinTask x64
'Peek... and Poke.. functions

'The Windows API GetCursorPos function gives the mouse cursor position.
'It requires as a parameter an address of a "point" structure.
'The structure is composed of 2 integers of 4 bytes each (LONG)
'with consecutive addresses. The first address contains the X coordinate.
'The second address contains the Y coordinate.

'Define memory address
dim addx as unsigned
dim addy as unsigned

'allocate memory starting at addx for the coordinates
'addx will contain the X coordinate
addx=allocate(8)

'addy will contain the Y coordinate
addy=addx+4

'Call the function in a loop
repeat
'address for structure addx is a parameter for GetCursorPos
a=External("user32.dll","GetCursorPos",addx)
if a <>0 then
'Read 4 bytes from memory at address addx (x position)
pos_x=PeekInteger(addx,4)
'Read 4 bytes from memory at address addy (y position)
pos_y=PeekInteger(addy,4)
'Display result
mes$="Cursor X is at : "+str$(pos_x)+"\n\Cursor Y is at : "+str$(pos_y)
msgframe(mes$,1)
pause 1
endif
until i=100
'the function loops for 100 seconds