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.
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).
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
fafalone
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.
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>
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.
Re: How twinBasic uses (references) standard DLLs
This place can be cruel on occasion :wave: but perhaps SDO is not familiar with TB having not used it so much.
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
wqweto
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.
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
fafalone
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
This place can be cruel on occasion :wave: 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.
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? :bigyello:
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
fafalone
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
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? :bigyello:
Very useful information.
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.
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
fafalone
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
1 Attachment(s)
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:
Attachment 195089
(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)
Re: How twinBasic uses (references) standard DLLs
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
fafalone
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:
Attachment 195089
(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.
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
fafalone
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:
Attachment 195089
(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.
Re: How twinBasic uses (references) standard DLLs
Fafalone SearchingDataOnly, any feedback is welcome.
If you have more declarations or properties, please post them.
Re: How twinBasic uses (references) standard DLLs
Quote:
Originally Posted by
yokesee
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.