Author Topic: COM OLE  (Read 3668 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
COM OLE
« on: March 12, 2021, 08:21:14 PM »
Charles,

I tried your COM OLE CallByName interface with my MASLink OCX that I'm using with SB.

Code: OxygenBasic
  1. ' O2 VB6
  2.  
  3. $filename "mlink.exe"
  4. uses  COM/COMutil
  5. CoInitialize null
  6.  
  7. CreateInterfaceByName "MASLink.OCXForm" mlobj
  8. CallByName(mlobj, "ShowOCXForm")
  9.  
  10. mlobj.Release
  11. CoUninitialize
  12.  

The window never shows.  :(  No errors, just the cursor does a quick busy icon and that's it.
« Last Edit: March 13, 2021, 05:54:52 AM by John »

JRS

  • Guest
Re: COM OLE
« Reply #1 on: March 13, 2021, 05:52:30 AM »
Here is what I'm trying to do in O2. I ran this script from the same COM folder as the O2 version.
Code: Script BASIC
  1. IMPORT COM.sbi
  2.  
  3. obj = COM::CREATE(:SET, "MASLink.OCXForm")
  4. COM::CBN obj, "ShowOCXForm"
  5.  
  6. COM::RELEASE obj
  7.  

Attached is what we should see.
« Last Edit: March 13, 2021, 11:28:51 PM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #2 on: March 14, 2021, 02:01:54 AM »
Hi John,

Does this SAPI callbyname example work on your system?

Code: [Select]
  '16:33 09/11/2020
  '10:01 14/03/2021
  'com automation
  '
  $filename "t.exe"
  'uses rtl64
  uses  COM/COMutil
  CoInitialize null
  CreateInterfaceByName "SAPI.SpVoice" voice
  'ConnectByName "SAPI.SpVoice", voice
  '
  BSTR r
  GetByName(voice,"volume",r) : print "vol " r
  GetByName(voice,"rate",r) : print "rate " r
  CallByName( voice,"speak", BSTR {"Hello World"} )
  LetByName(voice,"volume",7)
  LetByName(voice,"rate",3)
  CallByName( voice,"speak", BSTR {"Hello World","1"} )
  '
  'Working with variants
  ======================
  indexbase 1
  VARIANT va[2]
  va.vt[1]=VT_BSTR : va[1].bstrval="Hello Sky"
  va.vt[2]=VT_BSTR : va[2].lval=1
  CallByNameV( voice, METHOD,"speak", va,2 )
  del va.bstrval
  print err
  ...
  voice.Release
  CoUninitialize

JRS

  • Guest
Re: COM OLE
« Reply #3 on: March 14, 2021, 03:37:10 AM »
The clipboard SAPI and both COM webrowser examples worked fine. I'll give this example a try as well.

Update

It didn't work. I got the quick busy cursor but no "Hello World". (speakers on)

sapiDemo1.o2bas worked.

CallByName.o2bas didn't work.
« Last Edit: March 14, 2021, 03:54:54 AM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #4 on: March 14, 2021, 04:45:10 AM »
I have just uploaded my current version.

If you download it so we are in complete sync, and try again:

https://github.com/Charles-Pegge/OxygenBasic/blob/master/OxygenBasic030.zip

JRS

  • Guest
Re: COM OLE
« Reply #5 on: March 14, 2021, 12:34:10 PM »
Your updated O2 allows the above example to work. No luck with my VB6 OCX form.

It seems O2 isn't happy about the OCX taking over leaving O2 waiting for it to close. (guess) I will try and create a simple one button form with no SB dependencies and see if that works.
« Last Edit: March 14, 2021, 01:44:32 PM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #6 on: March 14, 2021, 03:35:40 PM »
Can you see whether it has given you an interface:

Code: [Select]
    ' O2 VB6
     
    $filename "mlink.exe"
    uses  COM/COMutil
    CoInitialize null
     
    CreateInterfaceByName "MASLink.OCXForm" mlobj
print err
print @mlobj
    CallByName(mlobj, "ShowOCXForm")
     
    mlobj.Release
    CoUninitialize

     

JRS

  • Guest
Re: COM OLE
« Reply #7 on: March 14, 2021, 03:44:24 PM »
No error and returns a handle.

Charles Pegge

  • Guest
Re: COM OLE
« Reply #8 on: March 14, 2021, 09:15:23 PM »
Okay.

Try CmdByName instead of CallByName. This is for calls that have no params

JRS

  • Guest
Re: COM OLE
« Reply #9 on: March 14, 2021, 09:49:36 PM »
Success!

Note: ScriptBasic is providing the Windows style support. (both SBC & SBW are compiled with style support)

Thanks Charles for all your effort in getting COM / OLE automation working in O2.
« Last Edit: March 14, 2021, 10:08:08 PM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #10 on: March 14, 2021, 10:30:57 PM »
Thanks John,

I will make CallByName a bit more flexible.

JRS

  • Guest
Re: COM OLE
« Reply #11 on: March 15, 2021, 04:14:59 PM »
I'm looking forward to getting VB6 events as callbacks to O2 for processing.

Charles,

Do you see any issues calling back to functions in the exe that started the program and calling the OCX? Will I need to use a DLL for callbacks including the COM\util tools?

« Last Edit: March 15, 2021, 10:52:06 PM by John »

JRS

  • Guest
Re: COM OLE
« Reply #12 on: March 16, 2021, 10:02:50 AM »
Charles,

This BOI script example gets the first customer in the table / file and displays the selected columns.  (BOI is the Sage version of Dave's COM extension for SB.  BOI = COM)

How can I pass an iDispatch pointer with CallByName?  Sage has a NewObject method that can inherit other COM/OLE objects.

Code: Script BASIC
  1. ' BOI - first customer - selected columns
  2.  
  3. IMPORT BOI.sbi
  4.  
  5. oscript = BOI::CREATE(:SET, "ProvideX.Script")
  6. BOI::CBN oScript, "Init", :CALL, "C:\\Sage\\Sage 100 Advanced ERP\\MAS90\\HOME"
  7. osession = BOI::CBN(oscript, "NewObject", :SET, "SY_Session")
  8. BOI::CBN osession, "nSetUser", :CALL, "JRS", "MyPassword"
  9. BOI::CBN osession, "nsetcompany", :CALL, "ABC"
  10. BOI::CBN osession, "nSetDate", :CALL, "A/R", "20171218"
  11. BOI::CBN osession, "nSetModule", :CALL, "A/R"
  12. ocust = BOI::CBN(oscript, "NewObject", :SET, "AR_Customer_svc", osession)
  13. BOI::CBN ocust, "nMoveFirst"
  14. CustomerNo$ = BOI::CBN(ocust, "sCustomerNo", :GET)
  15. CustomerName$ = BOI::CBN(ocust, "sCustomerName", :GET)
  16. City$ = BOI::CBN(ocust, "sCity", :GET)
  17. State$ = BOI::CBN(ocust, "sState", :GET)
  18. TelephoneNo$ = BOI::CBN(ocust, "sTelephoneNo", :GET)
  19. BOI::CBN ocust, "DropObject"
  20. BOI::CBN osession, "DropObject"
  21. BOI::RELEASE oscript
  22.  
  23. PRINT "Customer:  ", CustomerNo$, "  ", CustomerName$, "  ", City$, "  ", State$, "  ", TelephoneNo$, "\n"
  24.  

Output

C:\ScriptBASIC\examples>scriba firstcust.sb
Customer:  ABF  American Business Futures  Milwaukee  WI  (414) 555-4787

C:\ScriptBASIC\examples>


It looks like I can use the CallByNameV() function when I need to pass a VT_DISP long variable.
« Last Edit: March 17, 2021, 11:58:47 PM by John »

JRS

  • Guest
Re: COM OLE
« Reply #13 on: March 18, 2021, 12:37:25 PM »
I updated my firstcust.sb script to what I have installed on my Lenovo laptop.

Code: Script BASIC
  1. ' Sage BOI (Business Object Interface)- first customer - selected columns
  2.  
  3. IMPORT COM.sbi
  4.  
  5. oscript = COM::CREATE(:SET, "ProvideX.Script")
  6. COM::CBN oScript, "Init", :CALL, "C:\\Sage\\Sage 100 Standard\\MAS90\\Home"
  7. osession = COM::CBN(oscript, "NewObject", :SET, "SY_Session")
  8. COM::CBN osession, "nSetUser", :CALL, "js", "MY_PASSWORD"
  9. COM::CBN osession, "nsetcompany", :CALL, "ABC"
  10. COM::CBN osession, "nSetDate", :CALL, "A/R", "20171218"
  11. COM::CBN osession, "nSetModule", :CALL, "A/R"
  12. ocust = COM::CBN(oscript, "NewObject", :SET, "AR_Customer_svc", osession)
  13. COM::CBN ocust, "nMoveFirst"
  14. CustomerNo$ = COM::CBN(ocust, "sCustomerNo", :GET)
  15. CustomerName$ = COM::CBN(ocust, "sCustomerName", :GET)
  16. City$ = COM::CBN(ocust, "sCity", :GET)
  17. State$ = COM::CBN(ocust, "sState", :GET)
  18. TelephoneNo$ = COM::CBN(ocust, "sTelephoneNo", :GET)
  19. COM::CBN ocust, "DropObject"
  20. COM::CBN osession, "DropObject"
  21. COM::RELEASE oscript
  22.  
  23. PRINT "Customer:  ", CustomerNo$, "  ", CustomerName$, "  ", City$, "  ", State$, "  ", TelephoneNo$, "\n"
  24.  


C:\ScriptBASIC\sage>sbc firstcust.sb
Customer:  ABF  American Business Futures  Milwaukee  WI  (414) 555-4787

C:\ScriptBASIC\sage>


PowerShell's Measure-Command returns TotalSeconds      : 0.3442815 under ScriptBasic.

I'm working on converting this script to O2 COM/OLE.

I just noticed I wrote this original script on March 18, 2017.
« Last Edit: March 18, 2021, 01:29:26 PM by John »

JRS

  • Guest
Re: COM OLE
« Reply #14 on: March 18, 2021, 04:03:36 PM »
it doesn't look like O2 supports VT_DISP. (iDispatch variant type)

Code: OxygenBasic
  1. ' O2 Sage BOI
  2.  
  3. $filename "t.exe"                                    
  4. uses  COM/COMutil                                    
  5. CoInitialize null                                    
  6. CreateInterfaceByName "ProvideX.Script" oscript
  7. CallByName(oscript, "Init", BSTR {"C:\Sage\Sage 100 Standard\MAS90\Home"})
  8. VARIANT va[2]
  9.  
  10. va.vt[1]=VT_BSTR : va[1].bstrval="SY_Session"        
  11. va.vt[2]=VT_DISP
  12. CallByNameV(oscript, METHOD, "NewObject", va, 2)
  13. Print va[2].lval
  14.  
  15.  
  16. oscript.Release                                        
  17. CoUninitialize
  18.  
« Last Edit: March 18, 2021, 04:11:01 PM by John »