Author Topic: COM OLE  (Read 2330 times)

0 Members and 2 Guests are viewing this topic.

JRS

  • Guest
Re: COM OLE
« Reply #30 on: March 23, 2021, 10:23:43 AM »
I updated the COMutil.inc and tried your program. No errors or spreadsheet created. Never gets to Spreadsheet Created. messagebox.
« Last Edit: March 23, 2021, 10:34:36 AM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #31 on: March 23, 2021, 10:40:03 AM »
Some diagnostics to check valid Idispatch pointers

Code: [Select]
'07:01 23/03/2021
$filename "exceldemo.exe"
'uses RTL32                                   
uses  COM/COMutil                                   
 
 
string filename
int i, j
 
filename = "C:\OxygenBasic\examples\COM\exceldemo.xls"
CreateInterfaceByName "Excel.Application" oExcelApp
ObjectByName(oExcelApp, "Workbooks", BSTR {}, oWorkBook)
print @oWorkBook
ObjectByName(oWorkBook, "Add", BSTR {0}, oExcelWorkbook)
print @oExcelWorkbook
ObjectByName(oExcelWorkbook, "Worksheets", BSTR {1}, oExcelSheet)
print @oExcelSheet
ObjectByName(oExcelSheet, "Range", BSTR {"G3"}, oRange)
print @oRange
LetByName(oRange, "Value", 123)
oRange.Release
ObjectByName(oExcelSheet, "Range", BSTR {"B1:B5"}, oRange)
CallByName(oRange, "BorderAround", BSTR {1, -4138, 3})
ObjectByName(oRange, "Interior", BSTR {1}, oInterior)
LetByName(oInterior, "ColorIndex", 38)
LetByName(oInterior, "Pattern", "xlSolid")
oRange.Release
oInterior.Release
for i = 0 to 10
  for j = 0 to 10
    ObjectByName(oExcelSheet, "Cells", BSTR {i, j}, oCell)
    LetByName(oCell, "Value", "test-" + str(i) + "-" + str(j))
    oCell.Release
  next j   
next i   
CallByName(oExcelWorkbook, "SaveAs", BSTR {filename})
CmdByName(oExcelWorkbook, "Close")
CmdByName(oExcelApp, "Quit")
oExcelSheet.Release
oExcelWorkbook.Release
oWorkBook.Release
oExcelApp.Release
 
print "Speadsheet Created."

JRS

  • Guest
Re: COM OLE
« Reply #32 on: March 23, 2021, 10:44:57 AM »
I gave the Sage example a try with your new COMutil.inc

Code: OxygenBasic
  1. ' O2 Sage BOI
  2.  
  3. $filename "t.exe"                                    
  4. uses  COM/COMutil                                    
  5.  
  6.  
  7. CoInitialize null
  8.  
  9. CreateInterfaceByName "ProvideX.Script" oscript
  10. CallByName(oscript, "Init", BSTR {"C:\Sage\Sage 100 Standard\MAS90\Home"})
  11.  
  12. ObjectByName(oscript, "NewObject", METHOD, BSTR {"SY_Session"},osession)
  13. CallByName(osession, "nSetUser", BSTR {"js", "northstar"})
  14. CallByName(osession, "nsetcompany", BSTR {"ABC"})
  15. CallByName(osession, "nSetDate", BSTR {"A/R", "20210322"})
  16. CallByName(osession, "nSetModule", BSTR {"A/R"})
  17. ObjectByName(oscript, "NewObject", METHOD, BSTR {"AR_Customer_svc"}, osession, ocust)
  18. CmdByName(ocust, "nMoveFirst")
  19. GetByName(ocust, "sCustomerNo", customerno)
  20. GetByName(ocust, "sCustomerName", customername)
  21. GetByName(ocust, "sCity", city)
  22. GetByName(ocust, "sState", state)
  23. GetByName(ocust, "sTelephoneNo", telephoneno)
  24. CmdByName(ocust, "DropObject")
  25. CmdByName(osession, "DropObject")
  26.  
  27. ' print @osession 'check pointer
  28.  
  29. print "Customer:  ", customerno, "  ", customername, "  ", city, "  ", state, "  ", telephoneno
  30.  
  31. oscript.Release                                      
  32. CoUninitialize
  33.  


Charles Pegge

  • Guest
Re: COM OLE
« Reply #33 on: March 23, 2021, 10:47:38 AM »
You will need to remove the METHOD argument from objectByName.

JRS

  • Guest
Re: COM OLE
« Reply #34 on: March 23, 2021, 10:49:26 AM »
The new Excel example doesn't print anything.  :(

JRS

  • Guest
Re: COM OLE
« Reply #35 on: March 23, 2021, 10:53:18 AM »
I removed the METHOD tag from ObjectByName.

Code: OxygenBasic
  1. ' O2 Sage BOI
  2.  
  3. $filename "t.exe"                                    
  4. uses  COM/COMutil                                    
  5.  
  6.  
  7. CoInitialize null
  8.  
  9. CreateInterfaceByName "ProvideX.Script" oscript
  10. CallByName(oscript, "Init", BSTR {"C:\Sage\Sage 100 Standard\MAS90\Home"})
  11.  
  12. ObjectByName(oscript, "NewObject", BSTR {"SY_Session"},osession)
  13. CallByName(osession, "nSetUser", BSTR {"js", "northstar"})
  14. CallByName(osession, "nsetcompany", BSTR {"ABC"})
  15. CallByName(osession, "nSetDate", BSTR {"A/R", "20210322"})
  16. CallByName(osession, "nSetModule", BSTR {"A/R"})
  17. ObjectByName(oscript, "NewObject", BSTR {"AR_Customer_svc"}, osession, ocust)
  18. CmdByName(ocust, "nMoveFirst")
  19. GetByName(ocust, "sCustomerNo", customerno)
  20. GetByName(ocust, "sCustomerName", customername)
  21. GetByName(ocust, "sCity", city)
  22. GetByName(ocust, "sState", state)
  23. GetByName(ocust, "sTelephoneNo", telephoneno)
  24. CmdByName(ocust, "DropObject")
  25. CmdByName(osession, "DropObject")
  26.  
  27. ' print @osession 'check pointer
  28.  
  29. print "Customer:  ", customerno, "  ", customername, "  ", city, "  ", state, "  ", telephoneno
  30.  
  31. oscript.Release                                      
  32. CoUninitialize
  33.  

Charles Pegge

  • Guest
Re: COM OLE
« Reply #36 on: March 23, 2021, 11:00:19 AM »
line 17 extra arg: osession

ObjectByName(oscript, "NewObject", BSTR {"AR_Customer_svc"}, osession, ocust)



ps: ExcelApp?

CreateInterfaceByName "Excel.Application" oExcelApp
print @oExcelApp

JRS

  • Guest
Re: COM OLE
« Reply #37 on: March 23, 2021, 11:00:27 AM »
I added print @oExcelApp and it is ZERO.

The CreateInterfaceByName doesn't seem to be working with Excel.

JRS

  • Guest
Re: COM OLE
« Reply #38 on: March 23, 2021, 11:07:25 AM »
Quote
line 17 extra arg: osession

ObjectByName(oscript, "NewObject", BSTR {"AR_Customer_svc"}, osession, ocust)


Sage is creating the ocust object inheriting the osession object as an argument.

JRS

  • Guest
Re: COM OLE
« Reply #39 on: March 23, 2021, 11:11:27 AM »
print "ERROR: " + err

Charles Pegge

  • Guest
Re: COM OLE
« Reply #40 on: March 23, 2021, 11:14:55 AM »

JRS

  • Guest
Re: COM OLE
« Reply #41 on: March 23, 2021, 11:18:24 AM »
Hex value of error.

Charles Pegge

  • Guest
Re: COM OLE
« Reply #42 on: March 23, 2021, 11:27:14 AM »
Excel example requires CoInitialize null

0x800401F0

CO_E_NOTINITIALIZED

JRS

  • Guest
Re: COM OLE
« Reply #43 on: March 23, 2021, 11:40:46 AM »
Oops. I forgot to add Coinitialize null. Still generating an error.

Code: OxygenBasic
  1. '07:01 23/03/2021
  2. $filename "exceldemo.exe"
  3. 'uses RTL32                                  
  4. uses  COM/COMutil                                  
  5.  
  6. CoInitialize null
  7.  
  8. string filename
  9. int i, j
  10.  
  11. filename = "C:\OxygenBasic\examples\COM\exceldemo.xls"
  12. CreateInterfaceByName "Excel.Application" oExcelApp
  13. print "ERROR: " + hex(err)
  14. print @oExcelApp
  15. ObjectByName(oExcelApp, "Workbooks", BSTR {}, oWorkBook)
  16. print @oWorkBook
  17. ObjectByName(oWorkBook, "Add", BSTR {0}, oExcelWorkbook)
  18. print @oExcelWorkbook
  19. ObjectByName(oExcelWorkbook, "Worksheets", BSTR {1}, oExcelSheet)
  20. print @oExcelSheet
  21. ObjectByName(oExcelSheet, "Range", BSTR {"G3"}, oRange)
  22. print @oRange
  23. LetByName(oRange, "Value", 123)
  24. oRange.Release
  25. ObjectByName(oExcelSheet, "Range", BSTR {"B1:B5"}, oRange)
  26. CallByName(oRange, "BorderAround", BSTR {1, -4138, 3})
  27. ObjectByName(oRange, "Interior", BSTR {1}, oInterior)
  28. LetByName(oInterior, "ColorIndex", 38)
  29. LetByName(oInterior, "Pattern", "xlSolid")
  30. oRange.Release
  31. oInterior.Release
  32. for i = 0 to 10
  33.   for j = 0 to 10
  34.     ObjectByName(oExcelSheet, "Cells", BSTR {i, j}, oCell)
  35.     LetByName(oCell, "Value", "test-" + str(i) + "-" + str(j))
  36.     oCell.Release
  37.   next j  
  38. next i  
  39. CallByName(oExcelWorkbook, "SaveAs", BSTR {filename})
  40. CmdByName(oExcelWorkbook, "Close")
  41. CmdByName(oExcelApp, "Quit")
  42. oExcelSheet.Release
  43. oExcelWorkbook.Release
  44. oWorkBook.Release
  45. oExcelApp.Release
  46.  
  47. CoUninitialize
  48.  
  49. print "Speadsheet Created."
  50.  

Charles Pegge

  • Guest
Re: COM OLE
« Reply #44 on: March 23, 2021, 12:09:51 PM »
0x80004002

E_NOINTERFACE

do you get a CLSID ?

Code: [Select]
print guidtxt ObjectGuid