Date: 02-16-2022
Return to Index
created by gbSnippets
'Using DLLs requires that the the Exported Sub/functions be Declared before an
'application can use them. Local procedures, those in the PowerBASIC program
'do not require Declare statements (the compiler detects the procedures AND
'creates any needed declarations).
'There are 3 versions of Declare syntax supported by PowerBASIC:
Declare {Sub | Function} ProcName [BDECL | CDECL | SDECL] [LIB "LibName"] [ALIAS "AliasName"] [([arguments])] [AS Type]
Declare CallBack Function ProcName [[()] As Long]
Declare Thread Function ProcName (ByVal var AS (LONG | DWord}) AS {LONG | DWord}
'In general,
'Discussion of syntax:
Declare Function PBAppName LIB "mydll.dll" Alias "ExportName" (arglist)As Type
'1. PBAppName is what is used in the PowerBASIC program
'2. ExportName is the name and capitalization by which the Sub/Function was exported from the external DLL
'3. The DLL Name, following the LIB clause, must include the ".dll" extension
'4. If the Sub/Function has no arguments, Then the () is optional
'5. A type-specifier can be used to Declare the Type of a Function, but "As Type" syntax is recommended
'6. There can be zero Or more arguments. (arg1 as Type, arg2 as Type, ...)
'Here is the usual way in which a Declare is written (with a single argument in this example):
Declare Function PBAppName LIB "mydll.dll" Alias "ExportName" (arg as Long) As Long 'any legal Type
'These other variations are accepted by the PowerBASIC compiler also:
Declare Function PBAppName LIB "mydll.dll" Alias "ExportName" (arg&)As Long 'type-specifier used On arg variable
Declare Function PBAppName LIB "mydll.dll" Alias "ExportName" (Long) As Long 'arg variable is optional
Declare Function PBAppName LIB "mydll.dll" Alias "ExportName" ()As Long 'if there are no arguments
Declare Function PBAppName LIB "mydll.dll" Alias "ExportName" As Long 'with no arguments, parentheses are optional
'In all four variations, a type specifier can be applied to the function name (rather than use As Type at the end):
Declare Function PBAppName& LIB "mydll.dll" Alias "ExportName" (arg&) 'type-specifier used on arg variable
Declare Function PBAppName& LIB "mydll.dll" Alias "ExportName" (Long) 'arg variable is optional
Declare Function PBAppName& LIB "mydll.dll" Alias "ExportName" () 'if there are no arguments
Declare Function PBAppName& LIB "mydll.dll" Alias "ExportName" 'with no arguments, parentheses are optional
'gbs_00080
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm