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??
You should be able to put anything you like in a DLL - I'll see what I can do...
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.
I'm trying to call SETSCREEN in a DLL. but the DLL crashes.
The main code is :
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 :
FUNCTION start%:
SETSCREEN 1024,768,1
ENDFUNCTION
EXPORT start
It does look like non SDL stuff only can be in DLL's
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...
The wrapper (finally found it), does appear to be invalid :
// 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 (http://lists.libsdl.org/pipermail/sdl-libsdl.org/2005-January/048252.html)
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.
I dont think you can export global variables (if gives a warning if you try). Returning the values from a function is fine.
Mrtoad,
Hmm i had no such luck.
Do you have a working sample of passing numbers around into and out of a dll?
Try this :
DLL wrapper :
// 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 :
DEBUG test1()+"\n"
DEBUG test2()+"\n"
DLL :
GLOBAL A%=123
FUNCTION start%:
RETURN 43
ENDFUNCTION
FUNCTION start2%:
RETURN A%
ENDFUNCTION
EXPORT start
EXPORT start2
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
HEMLOS:
Quote from: MrTAToad on 2009-Oct-22
Try this :
DLL wrapper : --->>> (Project MakeDLL)
// 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)
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'
Indeed - two separate files :)
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.
You must put the dll in the same directory as the .exe
Here's a working exmple.
[attachment deleted by admin]