Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Using thincore.dll with Visual Basic 6.0

  1. #1
    Member
    Join Date
    Feb 2023
    Location
    London, Ontario, Canada
    Posts
    37
    Rep Power
    5

    Using thincore.dll with Visual Basic 6.0

    I would like to use thincore.dll with Visual Basic 6.0

    I looked in the \thinBasic\sdk\sdk.zip,
    and found thinBasic BASIC SDK\PB,
    which I could use as a reference for embedding in VB6.

    Before I do so,
    I was wondering if anyone has already created a thinBasic SDK for VB6,
    and would be interested in sharing it.

    My end goal is to create a COM DLL,
    which I can use with Visual Basic 6.0,
    Visual FoxPro 9.0,
    and other COM-callable languages.

    I occasionally use AutoIt, which comes with AutoItX, a DLL/COM control.
    Add AutoIt features to your favorite programming and scripting languages!
    Also features a C# assembly and PowerShell CmdLets.
    Perhaps a future addition to thinBasic could be something similar,
    maybe a thinBasicX COM DLL,
    which is what I am hoping to do with VB6 and thincore.dll

    Regards and Thanks,

    Joe

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

    thanks for your suggestion, I will check what I can do.
    thinBasic Core engine is written using Power Basic compiler and should definitely possible to develop COM components using it.

    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
    Member
    Join Date
    Feb 2023
    Location
    London, Ontario, Canada
    Posts
    37
    Rep Power
    5
    I'm having issues in getting thinCore.dll working with Visual Basic 6.0
    Option Explicit
    ' Microsoft Visual Basic 6.0 (SP6)
    ' Windows 10 [Version 10.0.19045.3693] 22H2
    '
    ' AddIn Used - Visual Basic 6 IDE Linker Addin
    ' - LinkSwitches /SUBSYSTEM:CONSOLE
    ' Ref: https://www.vbforums.com/showthread.php?866321-VB6-IDE-Linker-AddIn
    '
    ' Ref: https://github.com/ErosOlmi/ThinBASIC_On_GitHub/blob/master/Lib/thinCore.INC
    ' thinCore.dll is in my App.Path folder
    Declare Function thinBasic_Init Lib "thinCore.dll" (ByVal hWnd As Long, _
                                                        ByVal cInstance As Long, _
                                                        ByVal sKey As String) As Long
    Declare Function thinBasic_Release Lib "thinCore.dll" (ByVal hScript As Long) As Long
    Declare Function thinBasic_Run Lib "thinCore.dll" (ByVal hScript As Long, _
                                                        ByVal sBuffer As String, _
                                                        ByVal BufferType As Long, _
                                               Optional ByVal Options As Long, _
                                               Optional ByVal DebugMode As Long, _
                                               Optional ByVal LogMode As Long, _
                                               Optional ByVal ObfuscateMode As Long, _
                                               Optional ByVal CallingProgram As Long, _
                                               Optional ByVal DependancyMode As Long) As Long
                              
    Dim Con As New Console
    Dim hScript As Long
    Dim sScript As String
    Dim hRun As Long
    Const thinBasic_BufferType_IsFile = 0
    Sub Main()
      On Error GoTo CatchError
      sScript = "E:\Documents\vb6\ThinBasic\Alert.tBasic"
      Con.OutStd ("App.hInstance = " + Str$(App.hInstance))
      Con.OutStd ("App.Path      = " + App.Path)
      Con.OutStd ("Init")
      hScript = thinBasic_Init(0, App.hInstance, "")
      Con.OutStd ("Run")
      hRun = thinBasic_Run(hScript, sScript, thinBasic_BufferType_IsFile, 1 Or 2, False, False, False, 1, False)
      'Program quits here
      'From IDE: Run-time error '0'
      'From EXE: No error, Alert.tBasic is not run
      '
      'Output:
      'App.hInstance =  4194304
      'App.Path      = E:\Documents\vb6\ThinBasic
      'Init
      'Run
      Con.OutStd ("Release")
      thinBasic_Release (hScript)
      Exit Sub
    CatchError:
      Con.OutStd (Err.Number)
      Resume Next
    Return
    End Sub
    
    The program quits when thinBasic_Run is called.

    I have probably missed something in the translation of the Declare functions.

    Constructive assistance would be appreciated.

    Joe
    Attached Files Attached Files

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Sorry Joe, I forgot about this thread.

    If you change
    thinBasic_Init(0, App.hInstance, "")
    
    to
    thinBasic_Init(0, App.hInstance, "thinbasic")
    
    should work
    But there are other problems if you try to execute your script again using current thinCore.dll


    I'm making some fix to:
    • thinBasic_Init
    • thinBasic_Run
    • thinBasic_Release

    in order to make it working as an engine


    Attached a VB6 example with an update thinCore.dll that works better but still some problems.

    I will work on this next days and will be back.
    Attached Files Attached Files
    Last edited by ErosOlmi; 16-03-2024 at 11:50.
    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

  5. #5
    Member
    Join Date
    Feb 2023
    Location
    London, Ontario, Canada
    Posts
    37
    Rep Power
    5
    Thanks Eros,
    Your example works as described.

    I'm now trying to figure out how to modify a variable from VB6.

    For example;
    Dim sScript As String
        Dim hRun As Long
        Dim test As Long
        
        test = 1957
        
        Const thinBasic_BufferType_IsFile = 0
        Const thinBasic_BufferType_IsScript = 1
    
        On Error GoTo CatchError
      
        sScript = txt_thinBasicSourceCode.Text
        If Len(sScript) Then
            hScript = thinBasic_Init(0, App.hInstance, "thinbasic")
            If hScript = 0 Then
                hRun = thinBasic_Run(hScript, sScript, thinBasic_BufferType_IsScript, 1 Or 2, False, False, False, 1, False)
                'thinBasic_Release (hScript)
            End If
            Debug.Print thinBasic_VariableExists("test")
            Debug.Print test
        Else
            MsgBox "Please type some thinBasic code into textbox"
        End If
    
    Note I have created a Long variable called "test",
    and assigned a value of 1957.

    thinBasic_VariableExists("test") returns 1 if the variable exists, which it does.
    In the text box, if I add;
    long Test = 1960
    
    sMsg += Str(Test)
    
    ...before the MsgBox 0, sMsg, 1960 is returned in the MsgBox.

    The help file has a blank page for thinBasic_VariableExists, along with all of the other thinBasic_ functions.

    I was just guessing what the thinBasic_ functions do,
    but not being very successful.

    I did a review of \thinBasic\Lib\thincore.inc,
    but still having issues in understanding.

    How would I return the test variable,
    with a value of 1960, to VB6?

    Joe

  6. #6
    Member
    Join Date
    Feb 2023
    Location
    London, Ontario, Canada
    Posts
    37
    Rep Power
    5
    After a restful sleep, I've done some more research.

    I'm thinking that I have to use thinBasic_LoadSymbol

    I've declared it in VB6 as follows;
    Declare Function thinBasic_LoadSymbol Lib "thinCore.DLL" (ByVal SymbolName As String, ByVal ReturnCode As Long, ByVal FunctionOrSubPointer As Long, Optional ByVal ForceOverWrite As Long) As Long
    
    So, if I want to use thinBasic to increment a number from VB6 by 1,
    in VB6 the flow would go something like this...

    thinBasic_LoadSymbol "VB6AddOne", thinBasic_ReturnNumber, VarPtr(TBAddOne(20))
    
    VB6AddOne will be my new "keyword" (function) that I call in VB6.

    TBAddOne will be my function in thinBasic.

    I pass the number 20 in TBAddOne,
    which will increment by 1,
    and return 21.

    CODEPTR is not recognized by VB6,
    so I am using VarPtr.
    Not sure if this is the proper replacement.

    In the text box,
    I add the following function for thinBasic;
    function TBAddOne(theTest) as long
      function = theTest + 1
    end function
    
    As shown in attachment, I've got issues.
    image.png

    Constructive guidance would be appreciated.

    Joe
    Last edited by Joe Caverly; 17-03-2024 at 17:20.

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Hi Joe,

    will prepare an example next days.

    In the meantime refer to thinCore.inc file here https://github.com/ThinBASIC/module_...r/thinCore.inc that shows thinCore.dll exported functionalities you can use.

    thinBasic_LoadSymbol is used to add new keywords inside thinBasic. You need to have a compiled Sub/Function an map it in thinBasic passing its Sub/Function pointer.
    Then you will be responsible to parse thinBasic source code. This is a little complex but I can show you next days
    I do not know if VB6 has the possibility to have a pointer to a Sub/Function like CodePtr

    Anyway, to add a new variable use
    thinBasic_AddVariable
    You can just create a variable initializing it value and also create a variable that uses a memory area of your own VB6 variable passing optional parameter VarMemPtr

    Example for numeric (%VarSubType_Long = 5, refer to https://github.com/ThinBASIC/module_...r/thinCore.inc )
    call this before thinBasic_Run to add a variable of type LONG called MyLog with value 1234
    thinBasic_AddVariable("MyLong", "", 1234, %VarSubType_Long)
    

    call this before thinBasic_Run to add a variable of type LONG called MyLog that share the same memory area of your VB6 MyLongInVB6 LONG variable
    Dim MyLongInVB6 as long
    thinBasic_AddVariable("MyLong", "", 0, %VarSubType_Long, VarPtr(MyLongInVB6 ))
    
    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

  8. #8
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174
    Just as a hint: put an invisible (OUT OF VISIBLE RANGE ONLY) Textbox on your vb-form. Save the hwnd of it simply as Hex$ for a filename in an empty subfolder of your project. From thinbasic send

    Dword Htext =val("0x" & SHELL_CAPTUREOUTPUT("CMD /C DIR /A:-D /B " & app_scriptpath & "the_folder\*.*", "", %Sw_hide,10))
    Since its from same process you can use STRING sNUMERICS = mkbyt$(49,00,57,00,53,00,55,00,00)

    Thats "1957" in widechar with a terminating zero
    Then sendmessage(htext, %em_settext, sNumerics,-1)
    No more sure if it was -1 but it should do something as redraw or refresh the control.
    In vb your form should have a sub textbox1_textchange() that should fire up. Use val(textbox1.text) ...
    Last edited by ReneMiner; 18-03-2024 at 14:49.
    I think there are missing some Forum-sections as beta-testing and support

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Here attached a VB6 project in which I've injected a thinBasic variable connected to a VB6 variable so calling VB program can share variables with thinBasic script at runtime.

    The script evaluate a math expression over X with X from a min to a max with step

    ATTENTION: I've created a new thinCore.dll version for this script.
    There is a a new exported function called thinBasic_AddVariable_VB
    I did this because most of thinBasic API interfaces use EXTENDED numeric data type and EXTENDED (10 bytes) are not supported in VB6
    So I developed thinBasic_AddVariable_VB that accepts Doubles

    Hope this can help.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by ErosOlmi; 18-03-2024 at 22:33.
    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

  10. #10
    Member
    Join Date
    Feb 2023
    Location
    London, Ontario, Canada
    Posts
    37
    Rep Power
    5

    Thumbs up

    Thanks Eros!

    I've tried your sample out,
    and it works as documented.

    I will do some more testing over the next few days.

    Joe

Page 1 of 2 12 LastLast

Similar Threads

  1. Where is latest thincore.inc file?
    By gddeluca in forum thinBasic General
    Replies: 4
    Last Post: 05-07-2021, 00:39
  2. Visual free basic
    By ReneMiner in forum Other languages
    Replies: 0
    Last Post: 25-05-2021, 04:49
  3. thinCore as embeddable 3rd party DLL
    By ErosOlmi in forum Suggestions/Ideas discussions
    Replies: 21
    Last Post: 04-09-2009, 01:11
  4. Replies: 12
    Last Post: 13-06-2009, 22:00
  5. Need confirmation on thinCore speed
    By ErosOlmi in forum thinBasic General
    Replies: 18
    Last Post: 12-10-2007, 10:36

Members who have read this thread: 2

Posting Permissions

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