Am Sun, 16 Mar 2008 13:09:50 +0100 schrieb Wolfgang Enzinger:
> I'm currently trying to write a DLL in FreeBASIC for calling from VB.
> However, VB seems to load the DLL but cannot find my ex****ted procedure
> whatever I try.
OK, got this one solved. For the archives ...
**** <FreeBasic code> ****
'File: VBTest.bas
#include once "windows.bi"
#include once "win/ole2.bi"
EXTERN "windows-ms"
FUNCTION AddNumbers ( _
BYVAL operand1 AS INTEGER, BYVAL operand2 AS INTEGER ) _
AS INTEGER EX****T
RETURN operand1 + operand2
END FUNCTION
FUNCTION UpperCase(BYVAL arg AS ZSTRING PTR) AS BSTR EX****T
DIM res AS BSTR, s AS STRING
s = UCASE(*arg)
res = SysAllocStringByteLen(STRPTR(s), LEN(s))
RETURN res
END FUNCTION
END EXTERN
**** </FreeBasic code> ****
Compilation:
fbc.exe -dll -ex****t VBTest.bas
**** <VB code> ****
Option Explicit
Declare Function AddNumbers _
Lib "VBTest.dll" _
(ByVal operand1 As Long, ByVal operand2 As Long) _
As Long
Declare Function UpperCase _
Lib "VBTest.dll" _
(ByVal s As String) _
As String
Sub main()
Debug.Print AddNumbers(1, 2)
Debug.Print UpperCase("this is a test")
End Sub
**** </VB code> ****
> Wolfgang


|