Creating a DLL, question

Previous topic - Next topic

Hemlos

I know i cant use glbasic internals in a DLL file..
I cant seem to get any functions to do anything at all...everything gets ignored, except for the call to the function inside itself.

So my question is: What exactly can we put in a dll??

Bing ChatGpt is pretty smart :O

MrTAToad

You should be able to put anything you like in a DLL - I'll see what I can do...

Kitty Hello

mostly math functions. If you are using grapics, the DLL will open a complete new window, I'm uncertain, but I think you must call SETSCREEN before doing so.

MrTAToad

#3
I'm trying to call SETSCREEN in a DLL. but the DLL crashes.

The main code is :

Code (glbasic) Select
test()

FUNCTION p%:
ENDFUNCTION

INLINE
DECLARE_C(start, "test2.app/test2.dll", (void), void);
ENDINLINE

FUNCTION test%:
INLINE
if (start==NULL)
{
DEBUG("Here");
}
else
{
start();
}
ENDINLINE
ENDFUNCTION


And the DLL is :

Code (glbasic) Select
FUNCTION start%:
SETSCREEN 1024,768,1
ENDFUNCTION

EXPORT start


It does look like non SDL stuff only can be in DLL's

Kitty Hello

When you create a DLL, there will be a wrapper gbas created. Use that instead of INLINE.
It might be that it's buggy - noone ever used it AFAIK. That's what you get for implementing features just because people ask for it...

MrTAToad

#5
The wrapper (finally found it), does appear to be invalid :

Code (glbasic) Select
// Wrapper DLL
INLINE
}// namespace
#define DLL_NAME "tEST2.dll"
DECLARE_C_ALIAS(dll_start, DLL_NAME, "start", (), DGNat);
namespace __GLBASIC__ {
ENDINLINE


//!
//?
// \return     |

INLINE
return dll_start();
ENDINLINE
ENDFUNCTION


I think we can all spot the deliberate mistake :)

It still crashes in the DLL too...

Using SDL in a DLL does appear to be a common problem : http://lists.libsdl.org/pipermail/sdl-libsdl.org/2005-January/048252.html

Hemlos

QuoteIt might be that it's buggy - noone ever used it AFAIK. That's what you get for implementing features just because people ask for it...

Hehe, ya theres a wrapper bug, but i fixed that, it was obvious the syntax was off...sorry i didnt report this....

But thats not the end of the bugs....i think theres more because i surely did get the function to call properly, and with no compiler issues.
The next thing i noticed, variables...dont stick, i tried GLOBAL A=1 etc..

Oh ya, i found another issue......not dll related...if i declare GLOBAL in a function, it is not byref throughout the program.

Bing ChatGpt is pretty smart :O

MrTAToad

I dont think you can export global variables (if gives a warning if you try).  Returning the values from a function is fine.

Hemlos

Mrtoad,
Hmm i had no such luck.
Do you have a working sample of passing numbers around into and out of a dll?
Bing ChatGpt is pretty smart :O

MrTAToad

Try this :

DLL wrapper :
Code (glbasic) Select
// Wrapper DLL
INLINE
}// namespace
#define DLL_NAME "tEST2.dll"
DECLARE_C_ALIAS(dll_start, DLL_NAME, "start", (), DGNat);
DECLARE_C_ALIAS(dll_start2, DLL_NAME, "start2", (), DGNat);
namespace __GLBASIC__ {
ENDINLINE


FUNCTION test1%:
INLINE
return dll_start();
ENDINLINE
ENDFUNCTION

FUNCTION test2%:
INLINE
return dll_start2();
ENDINLINE
ENDFUNCTION


Test code :

Code (glbasic) Select
DEBUG test1()+"\n"
DEBUG test2()+"\n"


DLL :

Code (glbasic) Select
GLOBAL A%=123

FUNCTION start%:
RETURN 43
ENDFUNCTION

FUNCTION start2%:
RETURN A%
ENDFUNCTION

EXPORT start
EXPORT start2

Hemlos

Strange, i cant figgure out why i get this error.

linking:
gpc_temp1.o:gpc_temp1.cpp:(.text+0x72b0): multiple definition of `_start'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x1680): first defined here
gpc_temp1.o:gpc_temp1.cpp:(.text+0x72c0): multiple definition of `_start2'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x1690): first defined here
*** FATAL ERROR - Please post this output in the forum
Bing ChatGpt is pretty smart :O

Schranz0r

HEMLOS:

Quote from: MrTAToad on 2009-Oct-22
Try this :

DLL wrapper : --->>> (Project MakeDLL)
Code (glbasic) Select
// Wrapper DLL
INLINE
}// namespace
   #define DLL_NAME "tEST2.dll"
   DECLARE_C_ALIAS(dll_start, DLL_NAME, "start", (), DGNat);
   DECLARE_C_ALIAS(dll_start2, DLL_NAME, "start2", (), DGNat);
namespace __GLBASIC__ {
ENDINLINE


FUNCTION test1%:
   INLINE
      return dll_start();
   ENDINLINE
ENDFUNCTION

FUNCTION test2%:
   INLINE
      return dll_start2();
   ENDINLINE
ENDFUNCTION



DLL : ------->>>( Project DLLCall)

Code (glbasic) Select
GLOBAL A%=123

FUNCTION start%:
   RETURN 43
ENDFUNCTION

FUNCTION start2%:
   RETURN A%
ENDFUNCTION

EXPORT start
EXPORT start2


You need 2 different projects, one to create the DLL and one to load it... :)

see this:

multiple definition of `_start'
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

Indeed - two separate files :)

Kuron

QuoteIt might be that it's buggy - noone ever used it AFAIK.

I haven't used it, but I would like to.  However, I have never seen any documentation on how to properly create a DLL with GLBasic that can be used with other languages.

Kitty Hello

You must put the dll in the same directory as the .exe
Here's a working exmple.

[attachment deleted by admin]