Results 1 to 9 of 9

Thread: Creating Oxygen DLLs using thinBasic

  1. #1

    Creating Oxygen DLLs using thinBasic

    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.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    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

  3. #3
    Quote Originally Posted by ErosOlmi View Post
    This is another of the JIT magicians of Oxygen Basic !

    Thanks a lot Charles
    Eros
    I bet a lot of that O2 DLLC magic could easily materialize in TB without the need for a rabbit or a hat.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  4. #4
    Thank you very much Charles !
    Rob

  5. #5

    Dynamic Membrane - O2 DLL - a question

    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
    Attached Files Attached Files

  6. #6
    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.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  7. #7
    Member mike lobanovsky's Avatar
    Join Date
    Aug 2009
    Location
    Omnipresent
    Posts
    191
    Rep Power
    41
    ... 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)

  8. #8
    ... 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.
    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.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  9. #9
    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.

Similar Threads

  1. Creating PDF file from ThinBASIC
    By Petr Schreiber in forum Files and directories handling
    Replies: 6
    Last Post: 30-08-2020, 14:56
  2. Creating thinBasic keywords lists
    By ErosOlmi in forum Tips and Tricks
    Replies: 13
    Last Post: 29-12-2012, 03:45
  3. Replies: 12
    Last Post: 13-06-2009, 22:00
  4. Creating .exe from thinbasic scripts
    By Macros The Black in forum thinBundle
    Replies: 1
    Last Post: 02-06-2009, 09:36
  5. TOMDK - creating TB modules with Oxygen
    By Charles Pegge in forum Legacy
    Replies: 6
    Last Post: 21-08-2008, 06:31

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •