External functions: functions written in other languages stored in the dynamic link library.
1. External Functions
Steps for describing external functions:
1) first open the object to describe the external function;
2) In the script window, select declare from the first drop-down list box and Global External funnal or local external funnal from the second drop-down list box;
3) in the script window, enter the statements that describe the external functions;
4) Save the object;
Syntax of external functions:
{Access} function returndatatype name ({ref} datatype1 arg1 ,..., {Ref} datatypen argn}) Library "libname"
Alias for "extname"
Describes the syntax of the external process:
{Access} subroutine name ({ref} datatype1 arg1 ,..., {Ref} datatypen argn}) Library "libname"
Alias for "extname"
2. External function call example
1. Get the username information:
1.1 button Clicked:
Long ll_RTN
String ls_UserName
Long ll_BufferLen
Ll_BufferLen = MAX_LENGTH
Ls_UserName = Space (MAX_LENGTH)
// Obtain the name of the current system user
Ll_RTN = GetUserName (ls_UserName, ll_BufferLen)
If ll_RTN <> 0 Then
MessageBox ("prompt message", "the current system user name is:" + Trim (ls_UserName ))
Else
MessageBox ("prompt message", "function call failed! ")
End If
1.2 instance variable: CONSTANT Long MAX_LENGTH = 256
1.3 external functions:
FUNCTION Long GetUserName (REF String lpBuffer, REF Long nSize) LIBRARY "advapi32.dll" alias for "GetUserNameA"
2. Obtain the computer name:
2.1 button Clicked:
// Obtain the computer name
Long ll_RTN
String ls_ComputerName
Long ll_BufferLen
Ll_BufferLen = MAX_COMPUTERNAME_LENGTH + 225
Ls_ComputerName = Space (MAX_COMPUTERNAME_LENGTH + 225)
Ll_RTN = GetComputerName (ls_ComputerName, ll_BufferLen)
If ll_RTN <> 0 Then
MessageBox ("prompt message", "computer name:" + Trim (ls_ComputerName ))
Else
MessageBox ("prompt message", "function call failed! ")
End If
2.2 instance variable: CONSTANT Long MAX_COMPUTERNAME_LENGTH = 31
2.3 external functions:
FUNCTION Long GetComputerName (REF String lpBuffer, REF Long nSize) LIBRARY "kernel32" alias for "GetComputerNameA"