Better Header Support

Previous topic - Next topic

bigsofty

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.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Kitty Hello

please give fine examples how you want that. How do the other basics do that?

Schranz0r

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()

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad

I would prefer to be able to add C/C++ code as a seperate file (and thus add it via Add File in Projects)

Heiko

wait till tomorrow.i can post some examples for freebasic,
i wrote a wrapper for xors3d.dll

its easier than glbasic wrapping

Schranz0r

Brauchst du nicht, hab ich doch schon.
Mehr brauch da Gernot nicht für, um es sich zu veranschaulichen...
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

bigsofty

#6
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

Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Heiko

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.

Schranz0r

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
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

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.

Schranz0r

Joah, klingt gut :)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Heiko

#11
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.

Schranz0r

wird so nicht gehen!

PS.: keine Doppelposts!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Heiko

Mmmmm aber nen Ansatz ists, weiß nicht inwiefern was wie möglich ist.

bigsofty

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++.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)