GLBasic forum

Feature request => IDE/Syntax => Topic started by: bigsofty on 2008-Dec-19

Title: Better Header Support
Post by: bigsofty on 2008-Dec-19
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.
Title: Re: Better Header Support
Post by: Kitty Hello on 2008-Dec-19
please give fine examples how you want that. How do the other basics do that?
Title: Re: Better Header Support
Post by: Schranz0r on 2008-Dec-19
I found that:


freebasic:

Code: GLBasic [Select]
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

Code: GLBasic [Select]
.lib "BASSMOD.dll"

BASSMOD_GetVersion% () : "BASSMOD_GetVersion"
BASSMOD_ErrorGetCode% () : "BASSMOD_ErrorGetCode"
...
 

Than you can put it in the decl-folder to use it.

Code: GLBasic [Select]
Local Version = BASSMOD_GetVersion()

 
Title: Re: Better Header Support
Post by: MrTAToad on 2008-Dec-19
I would prefer to be able to add C/C++ code as a seperate file (and thus add it via Add File in Projects)
Title: Re: Better Header Support
Post by: Heiko on 2008-Dec-19
wait till tomorrow.i can post some examples for freebasic,
i wrote a wrapper for xors3d.dll

its easier than glbasic wrapping
Title: Re: Better Header Support
Post by: Schranz0r on 2008-Dec-19
Brauchst du nicht, hab ich doch schon.
Mehr brauch da Gernot nicht für, um es sich zu veranschaulichen...
Title: Re: Better Header Support
Post by: bigsofty on 2008-Dec-20
In FreeBasic to load a DLL...

C++ header...

Code: GLBasic [Select]
typedef int             (_stdcall *TGraphics)                           (int width, int height, int depth, int hertz, int flags);


Freebasic...

Code: GLBasic [Select]
        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...

Code: GLBasic [Select]
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...

Code: GLBasic [Select]
Declare Function Graphics

Informs the compiler that we will be calling our DLL sourced function as "Graphics"

Code: GLBasic [Select]
stdcall lib "engine"

...says that the call within the lib "engine".DLL will be stdcall (can be "cdecl" too)

Code: GLBasic [Select]
Alias "Graphics"

The name of the function as declared within the DLL.

Code: GLBasic [Select]
(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.

Code: GLBasic [Select]
as integer

...the function returns a pointer to an integer.


Ok, to unload the DLL...

Code: GLBasic [Select]
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

Title: Re: Better Header Support
Post by: Heiko on 2008-Dec-20
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.
Title: Re: Better Header Support
Post by: Schranz0r on 2008-Dec-20
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:


Code: GLBasic [Select]
FUNCTION BASS_LoadSample: id%, name$
    LOADEXTERNFUNCTION("bass.dll", LoadSample,(id%,name$))
    RETURN LoadSample(id%, name$)
ENDFUNCTION
Title: Re: Better Header Support
Post by: Kitty Hello on 2008-Dec-20
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.
Title: Re: Better Header Support
Post by: Schranz0r on 2008-Dec-20
Joah, klingt gut :)
Title: Re: Better Header Support
Post by: Heiko on 2009-Jan-19
Und gibts schon was neues Gernot?
Wäre cool, wenn Du was ins nächste Update basteln könntest.Please

EDIT:

Code: GLBasic [Select]
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.
Title: Re: Better Header Support
Post by: Schranz0r on 2009-Jan-30
wird so nicht gehen!

PS.: keine Doppelposts!
Title: Re: Better Header Support
Post by: Heiko on 2009-Jan-31
Mmmmm aber nen Ansatz ists, weiß nicht inwiefern was wie möglich ist.
Title: Re: Better Header Support
Post by: bigsofty on 2009-Jul-30
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++.
Title: Re: Better Header Support
Post by: Kitty Hello on 2009-Jul-30
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.
Title: Re: Better Header Support
Post by: Schranz0r 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:
Title: Re: Better Header Support
Post by: bigsofty 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: