Results 1 to 18 of 18

Thread: How twinBasic uses (references) standard DLLs

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    How twinBasic uses (references) standard DLLs

    I'd like to know how twinBasic uses (references) standard DLLs, e.g. how to use (references) the Cairo graphics library. Thanks.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,658

    Re: How twinBasic uses (references) standard DLLs

    The same way as VB6... Public Declare Function...

    For 64bit you'd follow the VBA7 syntax, Public Declare PtrSafe function....

    Precompiled DLLs can be found at e.g. https://github.com/preshing/cairo-windows/releases, and they have the C include headers you'd use for the API defs. It's not as friendly as RC6's wrappers, but this is how those are made (Olaf seems to have combined cairo with sqlite3 in a single dll, but it has the same dll exports for cairo).

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by fafalone View Post
    The same way as VB6... Public Declare Function...

    For 64bit you'd follow the VBA7 syntax, Public Declare PtrSafe function....

    Precompiled DLLs can be found at e.g. https://github.com/preshing/cairo-windows/releases, and they have the C include headers you'd use for the API defs. It's not as friendly as RC6's wrappers, but this is how those are made (Olaf seems to have combined cairo with sqlite3 in a single dll, but it has the same dll exports for cairo).
    Thank you, fafalone.

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,177

    Re: How twinBasic uses (references) standard DLLs

    This sounds like a fairly clueless question from a person building compilers and IDEs left and right. . . Go figure!

    cheers,
    </wqw>

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,658

    Re: How twinBasic uses (references) standard DLLs

    Also perhaps might be overstating twinBASIC's shortcomings if not even familiar enough with it to know that it references dlls just like VB6 and that functionality is very mature-- I can't even remember the last time a bug was found with DLL calls, since the va_list cdecl thing was more a new feature.

  6. #6
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,560

    Re: How twinBasic uses (references) standard DLLs

    This place can be cruel on occasion but perhaps SDO is not familiar with TB having not used it so much.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by wqweto View Post
    This sounds like a fairly clueless question from a person building compilers and IDEs left and right. . . Go figure!

    cheers,
    </wqw>
    Do you know why you've been learning C/C++ and VB for 30 years and still can't make a decent compiler or IDE?

    Because you always like to make pointless speculations, these boring words don't help you in any way, and they don't help anyone else.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by fafalone View Post
    Also perhaps might be overstating twinBASIC's shortcomings if not even familiar enough with it to know that it references dlls just like VB6 and that functionality is very mature-- I can't even remember the last time a bug was found with DLL calls, since the va_list cdecl thing was more a new feature.
    Quote Originally Posted by yereverluvinuncleber View Post
    This place can be cruel on occasion but perhaps SDO is not familiar with TB having not used it so much.
    Actually, I'm more familiar with twinBasic than you might imagine. I just want to see if twinBasic has some new and unexpected features, such as super simple methods for calling other language libs. For example, some languages can conveniently use C code or the C standard libs directly.

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,658

    Re: How twinBasic uses (references) standard DLLs

    Your question seemed aimed at Cairo, something not requiring any new features.

    But tB supports embedding static libraries... .lib and .obj; you define a symbol for it then write declare statements like a normal dll. There's two sample projects for this.

    There's some limitations; standard dependencies aren't fully implemented. VB6 compatibility is a higher priority but it will get there.

    Code:
    ' Compiled sqlite-amalgamation-3440200 (v3.44.2) 
    '   using cmdline (MSVC):  cl /c /Gw /Gy /GS- /DSQLITE_OMIT_SEH sqlite3.c
    #If Win64 Then
        Import Library "/Miscellaneous/sqlite3_64.obj" As SQLITE3 Link "stdlib", "kernel32"
    #Else
        Import Library "/Miscellaneous/sqlite3_32.obj" As SQLITE3 Link "stdlib", "kernel32"
    #End If
    
    Module MainModule
        
        Declare PtrSafe Function sqlite3_open CDecl Lib SQLITE3 (ByVal filename As String, ByRef ppDb As LongPtr) As Long
        Declare PtrSafe Function sqlite3_exec CDecl Lib SQLITE3 (ByVal pDb As LongPtr, ByVal sql As String, ByVal exec_callback As LongPtr, ByVal udp As LongPtr, ByRef errmsg As LongPtr) As Long
    ...
    Other features include CDecl support-- which extends to normal functions in code too, see my pdfium based pdf merger for example, the write callback has to be cdecl. Then vararg/va_list support, DeclareWide to disable Unicode<->ANSI shenanigans, overloading, and the ability to substitute LongPtr for UDTs. The last two apply to regular functions too.

    Then there's language features primarily aimed at helping interop like packing alignment and CType.

    Do you mean besides that because again these are all documented new features, with the major static linking feature having Sample projects shipped with the IDE, so maybe tB might be a little past some pre-alpha thing not worth taking seriously yet?

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by fafalone View Post
    Your question seemed aimed at Cairo
    Yes, you guessed exactly what I really meant. One of the main reasons why I have been reluctant to learn and use twinBasic in depth is that twinBasic does not have a heavyweight development framework like RC6. Right now, no third-party closed source libs are allowed in my projects, so I can't use RC6 in my project anymore (but RC6 can still be used in some testing tools). Finding a replacement for RC6 is almost impossible, and the only viable way now is to package the Cairo graphics library myself (or choose another graphics library). If twinBasic is better than VB6 on wrapping Cairo graphics library, then I could consider twinBasic for the job, but I need to get more information from you. It would be great if you could take the time to do a complete Cairo packaging example.

    Quote Originally Posted by fafalone View Post
    But tB supports embedding static libraries... .lib and .obj; you define a symbol for it then write declare statements like a normal dll. There's two sample projects for this.

    There's some limitations; standard dependencies aren't fully implemented. VB6 compatibility is a higher priority but it will get there.

    Code:
    ' Compiled sqlite-amalgamation-3440200 (v3.44.2) 
    '   using cmdline (MSVC):  cl /c /Gw /Gy /GS- /DSQLITE_OMIT_SEH sqlite3.c
    #If Win64 Then
        Import Library "/Miscellaneous/sqlite3_64.obj" As SQLITE3 Link "stdlib", "kernel32"
    #Else
        Import Library "/Miscellaneous/sqlite3_32.obj" As SQLITE3 Link "stdlib", "kernel32"
    #End If
    
    Module MainModule
        
        Declare PtrSafe Function sqlite3_open CDecl Lib SQLITE3 (ByVal filename As String, ByRef ppDb As LongPtr) As Long
        Declare PtrSafe Function sqlite3_exec CDecl Lib SQLITE3 (ByVal pDb As LongPtr, ByVal sql As String, ByVal exec_callback As LongPtr, ByVal udp As LongPtr, ByRef errmsg As LongPtr) As Long
    ...
    Other features include CDecl support-- which extends to normal functions in code too, see my pdfium based pdf merger for example, the write callback has to be cdecl. Then vararg/va_list support, DeclareWide to disable Unicode<->ANSI shenanigans, overloading, and the ability to substitute LongPtr for UDTs. The last two apply to regular functions too.

    Then there's language features primarily aimed at helping interop like packing alignment and CType.

    Do you mean besides that because again these are all documented new features, with the major static linking feature having Sample projects shipped with the IDE, so maybe tB might be a little past some pre-alpha thing not worth taking seriously yet?
    Very useful information.

  11. #11
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,658

    Re: How twinBasic uses (references) standard DLLs

    Sure, the standard DLL doesn't seem to be any kind of specialized implementation, so I can probably find a simple example to port as a proof of concept. I'll take a quick look at compiling the DLL from source myself but my C skills need quite a bit of improvement still. Though I've gotten quite good at porting it to VB/tB.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by fafalone View Post
    Sure, the standard DLL doesn't seem to be any kind of specialized implementation, so I can probably find a simple example to port as a proof of concept. I'll take a quick look at compiling the DLL from source myself but my C skills need quite a bit of improvement still. Though I've gotten quite good at porting it to VB/tB.
    That's great

  13. #13
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,658

    Re: How twinBasic uses (references) standard DLLs

    Ok so here's the simplest example possible just to show the approach.

    I used this set of precompiled binaries: https://github.com/preshing/cairo-wi...s/tag/with-tee

    With cairo.dll in the same folder as your .twinproj/exe (either 32bit or 64bit, this initial test can do either or but not both without changing the dll out), and a Form with CommandButton and PictureBox with AutoRedraw=True,

    Code:
    [SetDllDirectory(True)]
    Private Declare PtrSafe Function cairo_win32_surface_create CDecl Lib "cairo.dll" (ByVal hDC As LongPtr) As LongPtr
    Private Declare PtrSafe Function cairo_create CDecl Lib "cairo.dll" (ByVal target As LongPtr) As LongPtr
    Private Declare PtrSafe Sub cairo_set_source_rgb CDecl Lib "cairo.dll" (ByVal cr As LongPtr, ByVal red As Double, ByVal green As Double, ByVal blue As Double)
    Private Declare PtrSafe Sub cairo_rectangle CDecl Lib "cairo.dll" (ByVal cr As LongPtr, ByVal x As Double, ByVal y As Double, ByVal width As Double, ByVal height As Double)
    Private Declare PtrSafe Sub cairo_fill CDecl Lib "cairo.dll" (ByVal cr As LongPtr)
    Private Declare PtrSafe Sub cairo_surface_flush CDecl Lib "cairo.dll" (ByVal surface As LongPtr)
    Private Declare PtrSafe Sub cairo_destroy CDecl Lib "cairo.dll" (ByVal cr As LongPtr)
    Private Declare PtrSafe Sub cairo_surface_destroy CDecl Lib "cairo.dll" (ByVal surface As LongPtr)
    
    Private Sub CairoDrawTestRect(ByVal hDC As LongPtr, w As Double, h As Double)
        Dim surface As LongPtr = cairo_win32_surface_create(hDC)
        Dim cc As LongPtr = cairo_create(surface)
        cairo_set_source_rgb cc, 1.0, 0, 0
        cairo_rectangle(cc, 0, 0, w, h)
        cairo_fill(cc)
        cairo_surface_flush(surface)
        cairo_destroy(cc)
        cairo_surface_destroy(surface)
    End Sub
    
    Private Sub Command1_Click() Handles Command1.Click
        CairoDrawTestRect Picture1.hDC, 100, 100
        Picture1.Refresh
    End Sub
    That draws a 100x100 red square:

    Name:  ct.jpg
Views: 1387
Size:  7.9 KB

    (PS- The version I used was CDecl so if you wanted to share with VB6, you could either use The trick's VBCDeclFix to add support for that, or find/compile an alternate cairo.dll changing the calling convention to stdcall)
    Last edited by fafalone; Jul 2nd, 2025 at 12:37 AM.

  14. #14
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,560

    Re: How twinBasic uses (references) standard DLLs

    thanks Faf.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  15. #15
    Fanatic Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    630

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by fafalone View Post
    Ok so here's the simplest example possible just to show the approach.

    I used this set of precompiled binaries: https://github.com/preshing/cairo-wi...s/tag/with-tee

    With cairo.dll in the same folder as your .twinproj/exe (either 32bit or 64bit, this initial test can do either or but not both without changing the dll out), and a Form with CommandButton and PictureBox with AutoRedraw=True,

    Code:
    [SetDllDirectory(True)]
    Private Declare PtrSafe Function cairo_win32_surface_create CDecl Lib "cairo.dll" (ByVal hDC As LongPtr) As LongPtr
    Private Declare PtrSafe Function cairo_create CDecl Lib "cairo.dll" (ByVal target As LongPtr) As LongPtr
    Private Declare PtrSafe Sub cairo_set_source_rgb CDecl Lib "cairo.dll" (ByVal cr As LongPtr, ByVal red As Double, ByVal green As Double, ByVal blue As Double)
    Private Declare PtrSafe Sub cairo_rectangle CDecl Lib "cairo.dll" (ByVal cr As LongPtr, ByVal x As Double, ByVal y As Double, ByVal width As Double, ByVal height As Double)
    Private Declare PtrSafe Sub cairo_fill CDecl Lib "cairo.dll" (ByVal cr As LongPtr)
    Private Declare PtrSafe Sub cairo_surface_flush CDecl Lib "cairo.dll" (ByVal surface As LongPtr)
    Private Declare PtrSafe Sub cairo_destroy CDecl Lib "cairo.dll" (ByVal cr As LongPtr)
    Private Declare PtrSafe Sub cairo_surface_destroy CDecl Lib "cairo.dll" (ByVal surface As LongPtr)
    
    Private Sub CairoDrawTestRect(ByVal hDC As LongPtr, w As Double, h As Double)
        Dim surface As LongPtr = cairo_win32_surface_create(hDC)
        Dim cc As LongPtr = cairo_create(surface)
        cairo_set_source_rgb cc, 1.0, 0, 0
        cairo_rectangle(cc, 0, 0, w, h)
        cairo_fill(cc)
        cairo_surface_flush(surface)
        cairo_destroy(cc)
        cairo_surface_destroy(surface)
    End Sub
    
    Private Sub Command1_Click() Handles Command1.Click
        CairoDrawTestRect Picture1.hDC, 100, 100
        Picture1.Refresh
    End Sub
    That draws a 100x100 red square:

    Name:  ct.jpg
Views: 1387
Size:  7.9 KB

    (PS- The version I used was CDecl so if you wanted to share with VB6, you could either use The trick's VBCDeclFix to add support for that, or find/compile an alternate cairo.dll changing the calling convention to stdcall)
    Great work Faf,
    Great tool Cairo, it would be great to bring more features.

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by fafalone View Post
    Ok so here's the simplest example possible just to show the approach.

    I used this set of precompiled binaries: https://github.com/preshing/cairo-wi...s/tag/with-tee

    With cairo.dll in the same folder as your .twinproj/exe (either 32bit or 64bit, this initial test can do either or but not both without changing the dll out), and a Form with CommandButton and PictureBox with AutoRedraw=True,

    Code:
    [SetDllDirectory(True)]
    Private Declare PtrSafe Function cairo_win32_surface_create CDecl Lib "cairo.dll" (ByVal hDC As LongPtr) As LongPtr
    Private Declare PtrSafe Function cairo_create CDecl Lib "cairo.dll" (ByVal target As LongPtr) As LongPtr
    Private Declare PtrSafe Sub cairo_set_source_rgb CDecl Lib "cairo.dll" (ByVal cr As LongPtr, ByVal red As Double, ByVal green As Double, ByVal blue As Double)
    Private Declare PtrSafe Sub cairo_rectangle CDecl Lib "cairo.dll" (ByVal cr As LongPtr, ByVal x As Double, ByVal y As Double, ByVal width As Double, ByVal height As Double)
    Private Declare PtrSafe Sub cairo_fill CDecl Lib "cairo.dll" (ByVal cr As LongPtr)
    Private Declare PtrSafe Sub cairo_surface_flush CDecl Lib "cairo.dll" (ByVal surface As LongPtr)
    Private Declare PtrSafe Sub cairo_destroy CDecl Lib "cairo.dll" (ByVal cr As LongPtr)
    Private Declare PtrSafe Sub cairo_surface_destroy CDecl Lib "cairo.dll" (ByVal surface As LongPtr)
    
    Private Sub CairoDrawTestRect(ByVal hDC As LongPtr, w As Double, h As Double)
        Dim surface As LongPtr = cairo_win32_surface_create(hDC)
        Dim cc As LongPtr = cairo_create(surface)
        cairo_set_source_rgb cc, 1.0, 0, 0
        cairo_rectangle(cc, 0, 0, w, h)
        cairo_fill(cc)
        cairo_surface_flush(surface)
        cairo_destroy(cc)
        cairo_surface_destroy(surface)
    End Sub
    
    Private Sub Command1_Click() Handles Command1.Click
        CairoDrawTestRect Picture1.hDC, 100, 100
        Picture1.Refresh
    End Sub
    That draws a 100x100 red square:

    Name:  ct.jpg
Views: 1387
Size:  7.9 KB

    (PS- The version I used was CDecl so if you wanted to share with VB6, you could either use The trick's VBCDeclFix to add support for that, or find/compile an alternate cairo.dll changing the calling convention to stdcall)
    Thank you very much, fafalone. I'll use your code as a starting point to look at how to wrap a complete available Cairo lib in twinBasic.

  17. #17
    Fanatic Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    630

    Re: How twinBasic uses (references) standard DLLs

    Fafalone SearchingDataOnly, any feedback is welcome.
    If you have more declarations or properties, please post them.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: How twinBasic uses (references) standard DLLs

    Quote Originally Posted by yokesee View Post
    Fafalone SearchingDataOnly, any feedback is welcome.
    If you have more declarations or properties, please post them.
    Rewriting a Cairo-based UI lib is a job I have to do in the future, but I won't have time to start it until 18 months later.

    If twinBasic could provide an alternative to RC6, it will greatly increase the influence of twinBasic.

Posting Permissions

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



Click Here to Expand Forum to Full Width