Thanks!
A little example that shows how to use a DLL created with Visual Basic in DarkBasic Pro:
RemStart
**************************************************************************
This example shows how to use DLLs written in Visual Basic in DarkBasic
Pro. Visual Basic DLLs are ActiveX Dlls and unlike standard DLLs can't
be called using DarkBasic Pro's Load Dll and Call Dll commands.
ActiveX Dll can not only export functions (methods) but also variables
(properties). Both are encapsulated in Objects.
This example uses a DLL written in Visual Basic that has an object called
"TestClass" that exports three variables and four functions.
The variables are:
IntVar As Integer, FltVar As Single (float) and StrVar As String.
The functions are:
Function Mul(Val1 As Integer, Val2 As Integer) As Integer
Public Function AddFloats(Val1 As Single, Val2 As Single) As Single
Public Function ConcatStrings(Val1 As String, Val2 As String) As String
Public Function ShowMsg(Prompt As String)
**************************************************************************
RemEnd
` We use the LOAD COM DLL to load an COM/ActiveX Dll and one of its Class.
` This command allows us to use COM/ActiveX Dlls without needing to register them
` on the system.
Load Com Dll "AxDemo.Dll", "TestClass", 1
` Now we are ready to use this Dll and its class instance.
` First we'll write to and read from the variables it provides
Set Com Integer 1, "IntVar", 42
Set Com Float 1, "FltVar", 1.25
Set Com String 1, "StrVar", "This worked."
` So if everything worked as it should the following should print
` 42
` 1.25
` This worked.
Print Get Com Integer(1, "IntVar")
Print Get Com Float(1, "FltVar")
Print Get Com String(1, "StrVar")
Print
Print "Press a key to continue"
print
Wait Key
` Next we're going to call the functions.
` For this we're going to use the CALL COM FUNC commands. They're
` quite similar to the CALL DLL commands, except you need to specify
` what type of parameters you pass (if any). To do this use put
` Type Format String right after the function name. Each letter of this
` String represents the type of one of the following parameters.
` Let's start with the function "Mul". It takes 2 arguments, both of
` integer type. The letter for integer typesin the Type Format String is "I".
` Since there are two integer arguments the string should look like this: "II"
result = Call Com Func(1, "Mul", "II", 21, 2)
` The second function is called AddFloats. It takes two float arguments.
` A float value is represented by a "F" character. Therefore the Type Format
` string should look like this "FF"
result# = Call Com Func(1, "AddFloats", "FF", 1.2, 0.05)
` Next in line is the function ConcatStrings. Two arguments both of the type
` string (represented by the letter "S"
result$ = Call Com Func(1, "ConcatStrings", "SS", "This ", "worked.")
` Now let's print the results
Print result
Print result#
Print result$
` If all went well, it should print the same values as above
Print
Print "Press a key to continue"
` Finally we call a function named "ShowMsg", that'll pop up a
` Message box
Call Com Func 1, "ShowMsg", "S", "That's it. Thanks for running me. :-)"
` delete the COM/ActiveX instance
Delete Com 1
` the end
End
And the VB source
Public IntVar As Integer
Public StrVar As String
Public FltVar As Single
Public Function Mul(Val1 As Integer, Val2 As Integer) As Integer
Mul = Val1 * Val2
End Function
Public Function ShowMsg(Prompt As String)
dummy = MsgBox(Prompt, vbOKOnly)
End Function
Public Function ConcatStrings(Val1 As String, Val2 As String) As String
ConcatStrings = Val1 + Val2
End Function
Public Function AddFloats(Val1 As Single, Val2 As Single) As Single
AddFloats = Val1 + Val2
End Function