Im decently sure i was able to create and use .dll libraries like this maybe 10 years ago. Though they were not built in a same way than back then. They were just a file full of static functions.
So now im bit lost here. How i can use library like this?
' myType.bas
Type myType
public:
dim zxc as integer
declare function myFunction(someText as string) as string
End Type
function myType.myFunction(someText as string) as string
if len(someText) = 0 then
return "You are so quiet there"
end if
return "I thought so too"
end function
' myFile.bas
#inclib "myType"
dim myLib as myType
print myLib.myFunction("Hello")
fbc myFile.bas
myFile.bas(2) error 14: Expected identifier, found 'myType' in 'dim myLib as myType'
myFile.bas(4) error 265: Symbol not a CLASS, ENUM, TYPE or UNION type, before '.' in 'print myLib.myFunction("Hello")'
fbc -v
FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win32 (32bit)
Copyright (C) 2004-2021 The FreeBASIC development team.
standalone
target: win32, 486, 32bit
A dll is just binary code. Type definitions are not part of it. So there's no way a compiler can know what myType is from the DLL. Type definitions and function prototypes typically are in what C and C++ call "header files." In FB the convention is to put them in a file with a ".bi" extension while you then #include into your program that will link against the dll. The .bi files are only for the developer and the compiler; the resulting EXE only requires the DLLs. Hope this helps.
@caseih: I'm afraid, your response could be a little misunderstandable.
The Type definition has to be done in both the dll and the calling program. Using a .bi file is good custom (and recommendable), but it is not necessary.
Furthermore the procedure(s) of the dll have to be specified "Export".
' myType.bas
Type myType
Public:
Dim zxc As Integer
Declare Function myFunction(someText As String) As String
End Type
Function myType.myFunction(someText As String) As String Export
If Len(someText) = 0 Then
Return "You are so quiet there"
End If
Return "I thought so too"
End Function
' myFile.bas
#Inclib "myType"
Type myType
Public:
Dim zxc As Integer
Declare Function myFunction(someText As String) As String
End Type
Dim myLib As myType
Print myLib.myFunction("Hello")
Sleep
Last edited by grindstone on Jan 13, 2023 12:01, edited 1 time in total.
' myType.bas
#cmdline "-dll"
Type myType
public:
dim zxc as integer
declare function myFunction(someText as string) as string
End Type
function myType.myFunction(someText as string) as string export
if len(someText) = 0 then
return "You are so quiet there"
end if
return "I thought so too"
end function
#inclib "mytype"
Type myType
public:
dim zxc as integer
declare function myFunction(someText as string) as string
End Type
dim as mytype m
print m.myFunction("hello")
sleep
Creating a .bi file is optional, but for many functions in a library, (examples in the fb inc folder), then it is convenient.