Eine Dll-Function die mit char* returned ?

Previous topic - Next topic

Schranz0r

Hi Leutchen, und speziel Gernot!


Ich habe ein "leichtes" Problem mit der Umsetztung einer Function die wie folgt aussieht:

Code (glbasic) Select
char *BASS_GetDeviceDescription(
    DWORD device
);
Problem hierbei ist das char*, hab keine ahnung wie die Function aussehen muss....
Bei einen Parameter wärs ja leicht!

bei Name$:
Code (glbasic) Select
name_Str.c_str()Hab null Plan :(
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

Hehe.
Code (glbasic) Select
FUNCTION BASS_GetDeviceDescription$:
INLINE
   const char* pStr = BASS_GetDeviceDesctiption();
   if (pStr)
      return DGStr( pStr );
ENDINLINE
ENDFUNCTION

Schranz0r

Hmm Gernot geht nicht, da schmiert das Programm ab!

Code (glbasic) Select
INLINE
#define DLL "bass.dll"
#define DWord unsigned int
...
DECLARE_C_ALIAS(_BASS_GetDeviceDescription,DLL,"BASS_GetDeviceDescription",(DWord),char*);
...
ENDINLINE
Code (glbasic) Select
FUNCTION BASS_GetDeviceDescription$: device
INLINE
   const char* pStr = _BASS_GetDeviceDescription(device);
   if (pStr)
      return DGStr( pStr );
ENDINLINE
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

aha.
Was passiert, wenn Du die Zeile "if ... pStr); rauslässt? Evtl. schiert schon der Aufruf ab?
DECLARE_ALIAS (ohne _C_ evtl??)

Schranz0r

Es geht alles mit DECLARE_C_ALIAS, nur mit dem char* spinnt der rum...

Ohne das If ist es das gleiche... schmiert ab :(
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

sechsrad

denk dran, das ein string in  "c" immer mit einer +chr$(0) abschliessen muss.

ohne der null liest /schreibt er solange ein, bis er im speicher zufällig eine null findet oder schmiert ab.

mfg

Schranz0r

Wow sechsrad jetzt bin ich baff, du hast recht, und Gernot nämlich auch.

DECLARE_ALIAS und schon gehts!

Danke euch beiden !
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

Is this about using C strings from a DLL and storing them back in a GLB string variable?

Id be very interested in a quick run down in English of how you achieved this Schranz0r please?

P.S. It would be nice to have a GLB+C/C++ forum to collate all these valuable threads ;)
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)

sechsrad

QuoteDanke euch beiden !
jetzt hilf du mir mal bei einer einfachen dll mit dec-c++ und das einlesen dieser dll von dev-c++ in glbasic.

kannste ja in der pn reinsetzen oder mail : sechsrad@arcor.de

danke.

mfg

trucidare

DECLARE
DECLARE_C
DECLARE_Alias
DECLARE_C_ALIAS

wie was funzt schau in die hilfe ist nicht schwer (thema inline)

exportieren der funktionen mit extern "C" __declspec(dllexport) in devcpp
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

sechsrad

in der dev-c++-hilfe steht nichts  vom erstellen einer dll, es ist auch keine demo im verzeichnis,  wo gibt es die dazugehörigen demos für dec-c++.
mit google finde ich nichts dev-c++ > dll erstellen.

es ist ein graus.

mfg

Schranz0r

Genau so wie es trucidare sagt!
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

Code (glbasic) Select
extern "C" __declspec(dllexport) int __stdcall foo(int i)
{
 return ++i;
}
...dann als DLL compilieren.

in GLBASIC:

Code (glbasic) Select
INLINE
DECLARE(foo, "my.dll", (int), int);
ENDINLINE

FUNCTION glb_foo: i
INLINE
return foo(i);
ENDINLINE
ENDFUNCTION
...so aus'm Kopf raus.

sechsrad

hallo, gernot, suuuper. danke. es läuft.

die erste dll mit dev-c++, klasse.

damit kann ich aufbauen.

mfg

Schranz0r

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