Results 1 to 6 of 6

Thread: Wrapping Library with DLL

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    3
    Rep Power
    0

    Wrapping Library with DLL

    Hello all,

    New to thinBasic, but not Basic in general. I've coded in many different dialects of Basic over the years, QBasic, Visual Basic, PureBasic, etc. I tried looking at a few examples and I think I get it. I'm just wondering do I put the DLL in the same folder with the thinbasic wrapper resides, do I need the header files if its a C library?

    Say I wanted to wrap SDL2, would I do something like this?

    Const SDL_INIT_VIDEO = 32 'value converted to decimal from hex
    
    Type Rect
     x as single
     y as single
     w as single
     h as integer
    End Type
    
    Declare Function SDL_Init Lib "SDL2.dll" "Alias SDL_Init" (ByVal flags as single) as single
    
    Last edited by LeftyG; 08-02-2022 at 01:06.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10
    Ciao LeftyG

    welcome to thinBasic.

    Yes you did it almost, only Alias must be outside string of the alias. And data type, docs seem telling that SDL_Init accepts an v and returns an Integer

    Here an example. I do not know SDL but should work.
    uses "console"
    
    
    Const SDL_INIT_VIDEO = 32
     
    Type Rect
     x as single
     y as single
     w as single
     h as integer
    End Type
    
    
    'https://wiki.libsdl.org/SDL_Init
    Declare Function SDL_Init Lib "SDL2.dll" Alias "SDL_Init" (ByVal flags as UInt32) as Integer
    'https://wiki.libsdl.org/SDL_Quit
    Declare sub SDL_Quit Lib "SDL2.dll" Alias "SDL_Quit" ()
    
    
    integer iResult
    printl "Calling SDL_Init ..."
    iResult = SDL_Init(SDL_INIT_VIDEO)
    printl "Result: ", iResult
    if iResult <> 0 Then
      printl "An error occurred calling SDL_Init"
    else
      printl "Result was OK"
    end if
    
    
    WaitKey
    SDL_Quit
    
    Let me know.

    Ciao
    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
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10
    Quote Originally Posted by LeftyG View Post
    I'm just wondering do I put the DLL in the same folder with the thinbasic wrapper resides?
    Yes, put the DLL in the same folder where you have your thinBasic script or your bundled thinBasic exe.
    thinBasic will search for dll first in that folder.


    Quote Originally Posted by LeftyG View Post
    Do I need the header files if its a C library?
    You need to declare inside thinBasic the dll exported functions in order to use them. Keeping attention to correct data matching.

    I think someone in the past used SDL library here and created a list of declares
    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

  4. #4

  5. #5
    Junior Member
    Join Date
    Feb 2022
    Posts
    3
    Rep Power
    0
    Thanks. I figured out how to make a wrapper using a DLL.

  6. #6
    Member
    Join Date
    Jan 2017
    Location
    changsha China
    Age
    32
    Posts
    80
    Rep Power
    16
    Oh, we're kindred spirits, and this just requires a good translation of the header file.

Similar Threads

  1. Sdl Library
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 21
    Last Post: 14-05-2013, 16:38
  2. Maxim: Use of SDK for wrapping the Irrlicht
    By maxim in forum thinBasic SDK
    Replies: 12
    Last Post: 08-07-2011, 18:22
  3. Wrapping DLL functions bug
    By Bagamut in forum Xors3D Graphics Engine
    Replies: 7
    Last Post: 09-01-2011, 22:37
  4. 2D Library
    By Pipes in forum thinBasic General
    Replies: 11
    Last Post: 27-01-2009, 22:17
  5. GMP library: free library for arbitrary precision arithmetic
    By ErosOlmi in forum thinBasic vaporware
    Replies: 24
    Last Post: 03-01-2009, 01:01

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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