If I could completely wrap (stdcall, cdecl) C headers and dynamical link DLLs, all from within GLBasic, then I would no be put off by in-lining, which I current hate to be honest. FreeBasic, BlitzBasic, TrueBasic... all allow wrapping of DLLs from within their own syntax, its a feature I sorely miss. No easy addition though, I understand that, as it would require GLBasic to have at least full C++ type compatibility but I thought I would put in a request anyways.
please give fine examples how you want that. How do the other basics do that?
I found that:
freebasic:
dim PrintRot as sub (text as string)
dim Quadrat as function (a as double) as double
library = dylibload( "Library.dll" )
if library = 0 then
cls
?
? " DLL nicht gefunden."
sleep 1000,1
else
PrintRot = dylibsymbol( library, "PrintRot" )
quadrat = dylibsymbol( library, "Quadrat" )
PrintRot("Hallo Welt")
PrintRot(str$(Quadrat(5)))
sleep
End if
BlitzBasic:
Dll wrapping via *.DECL
.lib "BASSMOD.dll"
BASSMOD_GetVersion% () : "BASSMOD_GetVersion"
BASSMOD_ErrorGetCode% () : "BASSMOD_ErrorGetCode"
...
Than you can put it in the decl-folder to use it.
Local Version = BASSMOD_GetVersion()
I would prefer to be able to add C/C++ code as a seperate file (and thus add it via Add File in Projects)
wait till tomorrow.i can post some examples for freebasic,
i wrote a wrapper for xors3d.dll
its easier than glbasic wrapping
Brauchst du nicht, hab ich doch schon.
Mehr brauch da Gernot nicht für, um es sich zu veranschaulichen...
In FreeBasic to load a DLL...
C++ header...
typedef int (_stdcall *TGraphics) (int width, int height, int depth, int hertz, int flags);
Freebasic...
Print "Dylibload(engine.dll) Loading..."
Dim SHARED As Any Ptr hLib // Simply declare a big int, that is shared between all the FB source files to be used as lib pointer
hLib = Dylibload( "engine.dll" ) // Load the lib
If hLib = 0 Then
Print "Dylibload(engine.dll) failed"
ELSE
Print "Dylibload(engine.dll) Load OK"
Now to declare the function that exists within the DLL so that FreeBasic can use it...
Declare Function Graphics stdcall lib "engine" Alias "Graphics" (byval as integer, byval as integer, byval as integer, byval as integer, byval as integer) as integer
Looks complicated but its not...
Declare Function Graphics
Informs the compiler that we will be calling our DLL sourced function as "Graphics"
stdcall lib "engine"
...says that the call within the lib "engine".DLL will be stdcall (can be "cdecl" too)
Alias "Graphics"
The name of the function as declared within the DLL.
(byval as integer, byval as integer, byval as integer, byval as integer, byval as integer)
The parameters, "byval" means pass the actual value of the variable, "byref" would pass a pointer to the variable.
as integer
...the function returns a pointer to an integer.
Ok, to unload the DLL...
DyLibFree(hlib)
Some relevant commands manual pages...
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgDylibload
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgDylibfree
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgExport
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgAlias
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgDeclare
DLL Freebasic tutorial...
http://www.freebasic.net/wiki/wikka.php?wakka=TutInterfacingWithC
wobei die blitzbasic geschichte schon ein guter ansatz ist.
zum einen die declarationen, wo was in der dll zu finden ist.
und zum anderen optional eine funktion einbauen zu können, wenn mehr als nur parameter zu übergeben sind, mit rückgabewert.
also am einfachsten wäre es glaube ich in einer zeile eine methode aus einer dll aufrufen zu können, gleich mit werteübergabe und rückgabewert, falls vorhanden.
und alternativ anzubieten, dies auch in eine funktion abzuleiten, falls mehr als das von nöten ist.
würde auch ne Art Decl vorschlagen der im GLBasic Programmordner liegt, und sich die *.decl rauszieht und die Funktionen gleich in der IDE Highlightet / Einbindet !
Finde das auch die beste Lösung.
ODER:
Ein Befehl:
FUNCTION BASS_LoadSample: id%, name$
LOADEXTERNFUNCTION("bass.dll", LoadSample,(id%,name$))
RETURN LoadSample(id%, name$)
ENDFUNCTION
OK, ich bau euch was ein, das DECLARE so macht, dass man die Funktion auch so nutzen kann.
Problem sind die types. Ich werde nur diese Unterstützen:
void*, char, short, int, = DGNat
float, double = DGInt
char* = DGStr
also, alles was Zeiger braucht oder Felder or usertypes ist damit unmöglich.
Reicht i.d.R. aber für 90% alles aus.
Joah, klingt gut :)
Und gibts schon was neues Gernot?
Wäre cool, wenn Du was ins nächste Update basteln könntest.Please
EDIT:
GLOBAL LIBNAME = DyLoad "testdll.dll"
ProcFunktion(int) Funktionbla((int)werta = 1, (int)wertb), LIBNAME, _Funktionbla@0
sooooo hab mir mal gedanken gemacht....
wobei ProcFunktion(int) gleichzeitig den Rückgabewert bestimmt.also ein void oder einfaches leerlassen der klammern bedeutet eben kein Rückgabewert erwartet.
Vielleicht ists nicht perfekt, aber wenigstens ein Ansatz.
wird so nicht gehen!
PS.: keine Doppelposts!
Mmmmm aber nen Ansatz ists, weiß nicht inwiefern was wie möglich ist.
Kinda got confused by this bi-lingual thread :S Did it ever reach a decision? I still have a lot of external libraries I would like to link to GLBasic but really dislike using INLINE C++.
noone really told me how to wrap these files comfortably. But now that we have integers, there might be a solution.
I think I extend the DECLARE so it will produce real GLBasic commands instead. On my TODO now.
Quote from: Kitty Hello on 2009-Jul-30
I think I extend the DECLARE so it will produce real GLBasic commands instead. On my TODO now.
:good: :good: :good: :good: :good: :good:
Quote from: Schranz0r on 2009-Jul-30
Quote from: Kitty Hello on 2009-Jul-30
I think I extend the DECLARE so it will produce real GLBasic commands instead. On my TODO now.
:good: :good: :good: :good: :good: :good:
+ :good: :good: :good: :good: :good: :good: