Author Topic: Better Header Support  (Read 6928 times)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2606
    • View Profile
Better Header Support
« 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.
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)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Better Header Support
« Reply #1 on: 2008-Dec-19 »
please give fine examples how you want that. How do the other basics do that?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Better Header Support
« Reply #2 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()

 
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad

  • Guest
Re: Better Header Support
« Reply #3 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)

Offline Heiko

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 498
    • View Profile
Re: Better Header Support
« Reply #4 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
Ryzen 5 2400G - MSI B450 Tomahawk

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Better Header Support
« Reply #5 on: 2008-Dec-19 »
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 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2606
    • View Profile
Re: Better Header Support
« Reply #6 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

« Last Edit: 2008-Dec-20 by bigsofty »
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)

Offline Heiko

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 498
    • View Profile
Re: Better Header Support
« Reply #7 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.
Ryzen 5 2400G - MSI B450 Tomahawk

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Better Header Support
« Reply #8 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
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Better Header Support
« Reply #9 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.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Better Header Support
« Reply #10 on: 2008-Dec-20 »
Joah, klingt gut :)
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Heiko

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 498
    • View Profile
Re: Better Header Support
« Reply #11 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.
« Last Edit: 2009-Jan-30 by Schranz0r »
Ryzen 5 2400G - MSI B450 Tomahawk

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Better Header Support
« Reply #12 on: 2009-Jan-30 »
wird so nicht gehen!

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

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Heiko

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 498
    • View Profile
Re: Better Header Support
« Reply #13 on: 2009-Jan-31 »
Mmmmm aber nen Ansatz ists, weiß nicht inwiefern was wie möglich ist.
Ryzen 5 2400G - MSI B450 Tomahawk

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2606
    • View Profile
Re: Better Header Support
« Reply #14 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++.
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)