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

Thread: How to Reference a COM Method

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

    How to Reference a COM Method

    I have a number of VBScripts that are using vbRichClient RC6

    I am hoping that I can convert the VBScripts using the vbRichClient RC6 to thinBasic.

    Here I have converted a .VBS using the vbRichClient RC6 to .tbasicc
    uses "Console"
    
    dim rc6 as iDispatch
    
    printl "Creating rc6.cActiveScript object"
    
    rc6 = NewCom("rc6.cActiveScript")
    
    if IsComObject(rc6) Then
      rc6.ExecuteStatement("function Times2(theNumber):Times2=theNumber*2:end function:Product=Times2(10)")
      printl rc6.Eval("Product")
      rc6 = Nothing
    else
      printl "rc6 not created"
    end if
    
    Works as it should.

    So far, so good.

    Here's another .vbs that I am converting to .tbasicc
    Dim rc6 'as Object
    
    Const theDLL = "E:\Documents\vb6\DirectCOM\bin\JLCUtils.dll"
    Const theClass = "clsMath"
    
    Set rc6   = CreateObject("rc6.cRegFree")
    Set CScript = New Console
    
    Set clsMath = rc6.GetInstance(theDLL,theClass)
    CScript.Echo clsMath.ppp(6.59)
    
    Set clsMath = Nothing
    Set rc6 = Nothing
    
    Class Console
      Private fso
      Private stdout
      Private stderr
    
      Private Sub Class_Initialize()
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set stdout = fso.GetStandardStream(1)
        Set stderr = fso.GetStandardStream(2)
      End Sub
    
      Public Sub Echo(theArg)
        stdout.WriteLine theArg
      End Sub
    
      Private Sub class_Terminate()
        Set stderr = Nothing
        Set stdout = Nothing
        Set fso = Nothing
      End Sub
    End Class
    
    This .vbs code works as it should, that is, it allows Registration-Free use of COM DLLs.

    Here is my conversion to .tbasicc
    Uses "Console"
    Uses "Trace"
    
    Const theDLL = "E:\Documents\vb6\DirectCOM\bin\JLCUtils.dll"
    Const theClass = "clsMath"
    
    dim rc6 as iDispatch
    Dim clsMath as iDispatch
    
    rc6 = NewCom("rc6.cRegFree")
    
    if IsComObject(rc6) Then
      clsMath = rc6.GetInstance(theDLL,theClass)
      if IsComObject(clsMath) then
        Printl clsMath.ppp(6.59)
        clsMath = Nothing
      else
        printl "clsMath not created"
      end if
      rc6 = Nothing
    else
      printl "rc6 not created"
    end if
    
    ...which returns...
    clsMath not created
    
    Why is clsMath not being set to a COM object?
    Note that it sets rc6 to a COM object.

    How do I go about getting a reference to the rc6.GetInstance method,
    as I do in VBScript?

    Ref: https://www.vbforums.com/showthread....s-Docs-UPDATED!
    Ref: https://www.vbforums.com/showthread....ectCOM-amp-RC6
    Ref: https://www.vbrichclient.com/en/Downloads.htm

    Thanks from Joe

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    I can have a surprise in next thinBasic update.

    Where can I found JLCUtils.dll file?
    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
    34
    Rep Power
    5
    Quote Originally Posted by ErosOlmi View Post
    I can have a surprise in next thinBasic update.

    Where can I found JLCUtils.dll file?
    JLCUtils.dll is just a simple COM Server that I made for testing.

    You can download it from: https://drive.proton.me/urls/PXEWXB9GRW#yiZ1CvJ1L2bk

    Link expires January 27, 2024

    Thanks Eros.

    Joe

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    thinBasic has an undocumented NEWCOM syntax that allows creation of iDispatch class objects without the need to register you DLL into the registry.
    The only problem is that you need to know the ClassId of the class you want to use.
    So there is no need to create an instance of rc6.cRegFree and use it to load you unregistered DLL JLCUtils.dll

    Please try the following script and let me know.

    uses "Console"
    
    
    Dim clsMath as iDispatch
    
    '---Class ID for clsMath class
    $CLSID_clsMath = "{41A25489-48D5-4941-B792-FF9B20D32025}"
     
    clsMath = NEWCOM CLSID $CLSID_clsMath  LIB APP_SourcePath + "JLCUtils.dll"
     
    if IsComObject(clsMath) then
      Printl clsMath.ppp(6.59)
      clsMath = Nothing
    else
      printl "clsMath not created"
    end if
    
    
    printl "All done, press a key to end"
    WaitKey
    
    Last edited by ErosOlmi; 23-01-2024 at 01:48.
    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
    34
    Rep Power
    5
    Oh, wow!

    I copied jlcutils.dll and your script (jlcutils.tbasicc) over to my R:\ drive.

    Ran e:\thinbasic\thinbasicc.exe jlcutils.tbasicc

    Started up process explorer,
    and verified that it was using jlcutils.dll from my R:\ drive.

    Indeed it is!

    Thankyou very much for that!

    Makes things much easier!

    Joe

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Yes, you can put your COM dll in any place, just refer to its full path after LIB in:
    ... NEWCOM CLSID sClassId LIB sLibName
    
    This syntax was an experiment I did many month ago but never really finished and documented.
    I will do next thinBasic version

    Also I will add in thinAir a TypeLibrary browser, a program I derived from a Josè Roca developer that developed it in Power Basic many ears ago.
    It will help in understanding what's inside a COM DLL and get ClassIds of classes.
    Attached Images Attached Images
    Last edited by ErosOlmi; 23-01-2024 at 02:05.
    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

  7. #7
    Member
    Join Date
    Feb 2023
    Location
    London, Ontario, Canada
    Posts
    34
    Rep Power
    5
    Quote Originally Posted by ErosOlmi View Post
    Also I will add in thinAir a TypeLibrary browser, a program I derived from a Josè Roca developer that developed it in Power Basic many ears ago.
    It will help in understanding what's inside a COM DLL and get ClassIds of classes.
    That's the one I use also;
    tlb.jpeg

    Mine is probably a bit old,
    as I am using TypeLib Browser 5.0.1 from 2011

    Joe

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Quote Originally Posted by Joe Caverly View Post
    That's the one I use also;
    tlb.jpeg

    Mine is probably a bit old,
    as I am using TypeLib Browser 5.0.1 from 2011

    Joe
    Yes, more or lees is the same.
    I had source code from Josè so I was able to change some minor features like possibility to copy CLSID data in right treeview.
    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

  9. #9
    Member
    Join Date
    Feb 2023
    Location
    London, Ontario, Canada
    Posts
    34
    Rep Power
    5
    I can now easily use all of the RC6 classes in thinBasic.

    Here's the thinBasic method of using the RC6 ActiveScript Class,
    without having the need to have the RC6.dll registered in Microsoft Windows...
    uses "Console"
    'uses "Trace"
    
    Dim clsActiveScript as iDispatch
    
    '---Class ID for cActiveScript class
    $CLSID_cActiveScript = "{0961ABDC-07AA-483B-ADA0-55D14A2DEDCE}"
    
    printl APP_SourcePath + "rc6.dll"
    
    'These .dll files need to be in the same folder
    'cairo_sqlite.dll
    'DirectCOM.dll
    'RC6.dll
    'RC6Widgets.dll
    'WebView2Loader.dll
    
    clsActiveScript = NEWCOM CLSID $CLSID_cActiveScript  LIB "E:\Documents\vb6\RC6BaseDlls\rc6.dll"
    
    if IsComObject(clsActiveScript) then
      clsActiveScript.ExecuteStatement("function Times2(theNumber):Times2=theNumber*2:end function:Product=Times2(10)")
      printl clsActiveScript.Eval("Product")
    
      clsActiveScript.AddCode("function Times2(theNumber):Times2=theNumber*2:end function")
      printl clsActiveScript.Eval("Times2(15)")
    
      printl clsActiveScript.Eval("2023-1945")
    
      clsActiveScript = Nothing
    else
      printl "clsActiveScript not created"
    end if
    
    printl "All done, press a key to end"
    WaitKey
    
    Here's another, using the StringBuilder Class...
    uses "Console"
    
    Dim clsStringBuilder As iDispatch
    
    '---Class ID for cStringBuilder class
    $CLSID_cStringBuilder = "{8BF37C34-25F8-4605-BEF0-5069594FAA8C}"
    
    clsStringBuilder = NEWCOM CLSID $CLSID_cStringBuilder LIB "E:\Documents\vb6\RC6BaseDlls\rc6.dll"
    
    if IsComObject(clsStringBuilder) then
      clsStringBuilder.AddNl("One")
      clsStringBuilder.AddNl("Two")
      clsStringBuilder.AddNl("Three")
      printl clsStringBuilder.ToString
    
      clsStringBuilder = Nothing
    else
      printl "clsStringBuilder not created"
    end if
    
    printl "All done, press a key to end"
    WaitKey
    
    Joe

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Great!

    Happy you can have your job done in thinBasic and happy you can help me to better develop this part of thinBasic that can have a lot more to give.
    Will try to improve Newcom in order to have ClassName and not only ClassId for unregistered com server loaded directly from TypeLib DLL
    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

Page 1 of 2 12 LastLast

Similar Threads

  1. Smooth in-memory image display - what's the best method?
    By EmbeddedMan in forum UI (User Interface)
    Replies: 20
    Last Post: 29-09-2015, 17:18
  2. By Reference
    By peter in forum thinBasic General
    Replies: 4
    Last Post: 19-04-2013, 10:12
  3. Method to get Sprite-Pixel?
    By ReneMiner in forum TBGL module by Petr Schreiber
    Replies: 2
    Last Post: 19-11-2012, 17:10
  4. Improved donations method
    By ErosOlmi in forum Web and Forum
    Replies: 3
    Last Post: 03-12-2008, 18:40
  5. Irrlicht reference
    By ErosOlmi in forum Irrlicht
    Replies: 1
    Last Post: 05-05-2007, 02:13

Members who have read this thread: 9

Posting Permissions

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