silverfrost Site Admin

Joined: 29 Nov 2006 Posts: 191 Location: Manchester
|
Posted: Tue Sep 07, 2004 9:47 pm Post subject: Calling a Salford FTN95 DLL from Microsoft Visual Basic |
|
|
An FTN95 DLL that is called by an executable that uses the STDCALL calling convention (e.g. one created using Win32 Visual Basic) must use F_STDCALL in the declaration of all exported subprograms. For example,
Code: | F_STDCALL FUNCTION F(X)
INTEGER F,X
F=X
END |
Such a function could make calls to Windows API functions provided an interface is provided via, for example, "USE MSWIN" or "INCLUDE <windows.ins>". Alternatively an interface for each API function can be given explicitly. For example,
Code: | STDCALL SENDMESSAGE 'SendMessageA' (VAL,VAL,VAL,VAL):INTEGER*4 |
A call is automatically made to a DLL function called LIBMAIN when the DLL is loaded. If you do not provide a definition of LIBMAIN then SLINK will provide a default for you. LIBMAIN is used to initialise global data. It takes the following form.
Code: | F_STDCALL INTEGER FUNCTION LIBMAIN(hInst,ul,lpR)
INTEGER hInst,ul,lpR
!***** Initialise global data here
LIBMAIN=1
END |
A simple SLINK script would take the form:
Code: | dll
lo f95.obj
exportall
file c:windowsf95.dll |
A Visual Basic program can use calls to the API functions LoadLibrary and FreeLibrary in order to ensure that the DLL does not unload whilst a Visual Basic form is loaded. Here is some sample code for this purpose.
Code: | Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal s As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (h As Long) As Long
Dim hLibModule As Long
Private Sub Form_Load()
hLibModule = LoadLibrary("f95.dll")
End Sub
Private Sub Form_Unload(Cancel As Integer)
i& = FreeLibrary(hLibModule)
End Sub |
|
|