guides:programming:programmers_reference_manual:calling_a_function_in_a_dll_from_basic

Calling a Function in a DLL from BASIC+

Once the prototype record has been defined, and the BASIC+ callable functions have been created using Declare_FCNS, you can call the functions from BASIC+ as if they were BASIC+ stored procedures.

Use the Declare Function statement if a return value is required from the DLL function; use the Declare Subroutine statement if the function does not return a value, or if the return value will be ignored.

In the following example, the Windows functions MessageBeep and MessageBoxA (the ANSI version of MessageBox()) are used to inform the user of a problem. The return value from MessageBeep is discarded; the return value from MessageBoxA is used to determine whether or not to abort.

The function prototypes for MessageBeep and MessageBox, in the DLL_USER32 prototype record in the SYSPROCS table, are as follows:

INT STDCALL MessageBeep(UINT)

INT STDCALL MessageBoxA(HANDLE,LPCHAR,LPCHAR,UINT) AS MessageBox

In the function prototype, both MessageBeep() and MessageBoxA() return an INT. MessageBeep() is declared as a subroutine because its return value is not used. However, MessageBoxA() is declared as a function because its return value is used (to determine which button the user clicked on).

See the MESSAGE_BOX_EQUATES insert for the equated constants.

Declare Subroutine MessageBeep

Declare Function MessageBox

$INSERT MESSAGE_BOX_EQUATES

MessageBeep(MSG_ICON_STOP$)       ;      * Critical stop sound

Ret = MessageBox(0, "Abort?", "Error", MSG_BTN_YESNO$)

If Ret = MSG_RET_YES$ Then

   Return 0;      * Abort procedure

End Else

   * continue with the procedure

End

Note: Function prototypes for 32 bit Windows DLLs are declared in the DLL_USER32 prototype record in the SYSPROCS table. Function prototypes for 16 bit Windows DLLs are declared in the DLL_USER prototype record in the SYSPROCS table.

  • guides/programming/programmers_reference_manual/calling_a_function_in_a_dll_from_basic.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1