This is another of the JIT magicians of Oxygen Basic !
Thanks a lot Charles
Eros
OxygenBasic can be used to create general-use DLLs. You can also test them at the same time within the envelope of a single thinBasic script.
To create independent DLLs, a run-time library source needs to be embedded. I have included RTL32 with the latest thinBasic_Oxygen here in examples/DLL/
http://www.thinbasic.com/community/s...ad.php?t=12175
To expose any function, all you need to do is add export to its prototype.
The code for terminating the DLL (before the DLL is unloaded) is automatically generated.
Hello World Example
uses "oxygen" dim src as string src=" % filename "t.dll" % dll include "RTL32.inc" function hello(byval name as string) as string, export return "Hello "+name end function " 'end src o2_basic src if o2_errno then msgbox 0, o2_error stop else o2_exec end if 'TEST declare function hello lib "t.dll" alias "hello" (byval name as string) as string msgbox 0,hello("World!")
Last edited by Charles Pegge; 31-12-2013 at 13:19.
This is another of the JIT magicians of Oxygen Basic !
Thanks a lot Charles
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Hi all,
Wrote something using a DLL generated by O².
(attached)
However, can I allocate memory from and within the DLL that can be linked (later) by TB ? (Here the array is created in TB and linked by O² -- I like to do it the reverse way -- if this is possible ?)
(or shorter, can a DLL allocate memory of its own that can be linked ?)
best Rob
The O2 DLL is in the same process as TB and as long as you have a pointer to the memory you created in O2, it should addressable in TB.
... unless you unload this DLL with an explicit or unfortunate call to FreeLibrary() in either thinBasic or OxygenBasic code. The process will continue to run but all the memory pointers created by the DLL will become invalid. From this standpoint, it's safer to allocate memory in the caller code rather than in the callee.
Mike
(3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)
In ScriptBasic using a C based extension module (like the IUP interface) I assign global variables in the callback routines and return to SB. I then call the (already loaded) extension module again returning these previously set global variables. Before I return to SB I reset them back to their default state. As Mike said, variable values assigned within an exportable function are lost on the return.... unless you unload this DLL with an explicit or unfortunate call to FreeLibrary() in either thinBasic or OxygenBasic code. The process will continue to run but all the memory pointers created by the DLL will become invalid.
Normally one would expect the DLL to remain in process until the thinBasic program terminates.
An Oxygen DLL will automatically release all its global/static resources when the DLL is freed.
a procedure called finish() can be used to explicitly shut down any activities and resources, not controlled directly by the Oxygen runtime (GDIplus for example). If finish is not present in the source code, the following minimal implementation is automatically added in.
a
sub finish() external
terminate
end sub
this procedure is indirectly called when FreeLibrary is invoked by thinBasic to unload the DLL.
Last edited by Charles Pegge; 05-01-2014 at 21:00.
Bookmarks