Navigation: thinBasic language > Script structure > External function declarations > Declare Set ADDRESS |
|
Description
Set function or sub address to a previously general declared function or sub.
Syntax
DECLARE SET { ADDRESS | AT } GeneralFunctionName, ProcAddress
Returns
None
Parameters
Name |
Type |
Optional |
Meaning |
GeneralFunctionName |
An unique name |
No |
Name of a previously declared general function or sub. |
ProcAddress |
Numeric |
No |
Process address to be assigned to general declared function or sub. |
Remarks
Syntax can be either:
DECLARE SET ADDRESS ...
or
DECLARE SET AT ...
Restrictions
See also
Examples
'---
'---Standard API functions to get a function address. Those functions are used to simulate Petr SomeDirtyAPIToTellMeHandle function
'---
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (lpLibFileName As ASCIIZ) As Long
Declare Function GetProcAddress Lib "KERNEL32.DLL" Alias "GetProcAddress" (ByVal hModule As DWORD, lpProcName As ASCIIZ) As Long
'---Commented line is a standard API declare for IsCharUpper function. We will not use this way in this example but ... (see next comment)
'DECLARE FUNCTION IsCharUpper LIB 'USER32.DLL' ALIAS 'IsCharUpperA' (BYVAL cChar AS BYTE) AS LONG
'--- ...we will tell thinBasic you are defining a generic function not jet initialized (ie, library and address are missing)
Declare Function IsCharUpper (ByVal cChar As Byte) As Long
'---OK, here we start simulating the assigment of the procedure address
Dim hLib As Long
Dim hProc As Long
'---First we need to load the library from where we want the address of the function
hLib = LoadLibrary("USER32.DLL")
'---If return value is NOT zero all is ok
If hLib <> 0 Then
'---Now we try to get the address of the prodecure inside the library
hProc = GetProcAddress(hLib, "IsCharUpperA")
'---If return value is NOT zero all is ok
If hProc <> 0 Then
'---
'---Here the new thinBasic functionality. It assign a process address to a generic previously declared function allowing subsequent calling
Declare Set ADDRESS IsCharUpper, hProc
'---So we are telling thinBasic that the previous declared function 'IsCharUpper' has now its process address
'---Now we try to use the new functionality that will tell us if a char is upper or not
Dim Char As String VALUE "F"
Dim AsciiChar As Byte VALUE ASC(Char)
MSGBOX 0, "OK. IsCharUpper for char " & Char & " returned: " & IsCharUpper(AsciiChar) & " (1=true and 0= false)"
Else
MSGBOX 0, "It was not possible to get the procedure address"
End If
Else
MSGBOX 0, "It was not possible to load library"
End If
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |