Author Topic: COM  (Read 5637 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Re: COM
« Reply #30 on: November 03, 2020, 01:22:16 PM »
I'm running Windows 10 Pro and have no issues with Dave's code.

Were you able to get it to work on Win7 or Vista?

Dave has a debug print setup with the SB extension. I will enable the flag and post the results of calling the SAPI example you are trying to get working. Who knows, it might help.
« Last Edit: November 03, 2020, 11:18:59 PM by John »

JRS

  • Guest
Re: COM
« Reply #31 on: November 03, 2020, 10:59:43 PM »
Here is the debug trace from the SB COM extension module and the SAPI example.

Code: Script BASIC
  1. IMPORT com.sbi
  2.  
  3. voice = COM::CREATE(:SET, "SAPI.SpVoice")
  4. COM::CBN(voice, "speak", :CALL, "Hello World")
  5.  
  6. COM::RELEASE(voice)
  7.  


Charles Pegge

  • Guest
Re: COM
« Reply #32 on: November 05, 2020, 12:47:45 PM »
Thanks John,

My IDispatch functions were declared in the wrong order, so now we are back in business.

JRS

  • Guest
Re: COM
« Reply #33 on: November 05, 2020, 12:57:50 PM »
I never lost confidence in you. Persistence is the key to all rewards.

Having COM/OLE automation support in O2 will open up a huge array of plug in functionality too difficult and time consuming done at a low level.

I just made my computer talk with 3 lines of code.
« Last Edit: November 05, 2020, 01:36:14 PM by John »

Brian Alvarez

  • Guest
Re: COM
« Reply #34 on: November 07, 2020, 09:08:10 PM »
Thanks John,

My IDispatch functions were declared in the wrong order, so now we are back in business.

Good stuff!  ;D

Charles Pegge

  • Guest
Re: COM
« Reply #35 on: November 10, 2020, 01:52:41 PM »
My proposed syntax for COM automation:
Code: [Select]
  uses  COM/COMutil
  CoInitialize null
  CreateInterfaceByName "SAPI.SpVoice" voice
  CallByName( voice, "speak", {"Hello World"} )
  ...
  voice.Release
  CoUninitialize

CallByName converts all arguments into BSTRs, and also supports return values with an optional extra param.


JRS

  • Guest
Re: COM
« Reply #36 on: November 10, 2020, 03:59:24 PM »
Looking good!

How does one indicate a LET, GET and SET (object ref)?

The above assumes a method call.

Not sure making all passed arguments BStr will work. I have many methods that are expecting a long/int.

Minimum you need to be able to pass strings, long/int, floats and iDispatch pointers.

How about the following syntax?

LetByName()
GetByName()
SetByName()

com_arg = VT_STRING::"Hello World"

Variant casting would be nice.
« Last Edit: November 11, 2020, 06:44:48 PM by John »

JRS

  • Guest
Re: COM
« Reply #37 on: November 11, 2020, 06:57:56 PM »
Here is a ScriptBasic COM script to get the first customer from Sage 100 accounting software. It's a good example as it uses most of the COM syntax.


This BOI script example gets the first customer in the table / file and displays the selected columns.

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>


Note: BOI is the same reference as COM. (Different include file)

JRS

  • Guest
Re: COM
« Reply #38 on: November 11, 2020, 08:16:03 PM »
Here is how my ScriptBasic and VB6 project turned out.

(Windows 10 Pro and Windows Server 2012 R2)

I even have VB6 IDE running on Windows Server 2012 R2.

« Last Edit: November 12, 2020, 10:46:01 PM by John »

Charles Pegge

  • Guest
Re: COM
« Reply #39 on: November 11, 2020, 09:28:38 PM »
Hi John,
Further proposed:
Code: [Select]
  uses  COM/COMutil
  CoInitialize null

  CreateInterfaceByName "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"} )
  '
  VARIANT va
  va.vt=VT_BSTR : va.bstrval="Hello Sky"
  CallByNameV( voice, METHOD,"speak", va,1 )
  del va.bstrval
  'print err

  'CallByNameS( voice,1, "speak", BSTR {"Hello World"},countof )
  ...
  voice.Release
  CoUninitialize
« Last Edit: November 12, 2020, 07:18:37 AM by Charles Pegge »

JRS

  • Guest
Re: COM
« Reply #40 on: November 12, 2020, 06:26:01 AM »
That looks great Charles!

Can't wait to give it a try when your ready to release something.

JRS

  • Guest
Re: COM
« Reply #41 on: November 12, 2020, 11:06:38 AM »
I'm looking for a way to call an ActiveX DLL method (OLE server) as a self running 'thread' returning once it has been called.

I wonder if I put my code in the OnLoad function that would do it?
« Last Edit: November 12, 2020, 12:26:00 PM by John »

JRS

  • Guest
Re: COM
« Reply #42 on: November 12, 2020, 09:06:21 PM »
I found a multi-threading VB example to display a Mandelbrot. (zoomable - select a section of the image and it will display that region)

I attached the source zip as well.

JRS

  • Guest
Re: COM
« Reply #43 on: November 13, 2020, 09:48:43 PM »
Theo posted this on the JRS form. It's a public domain COM/OLE automation DLL but interface specific. (SAPI, Excel, Word and ADODB) It has Liberty Basic and C source examples. It might be worth taking a peek.

Quote
TTS DLL and TTW DLL are Dynamically Linked Libraries that contain 17 function calls between them. The function calls
cover Text-To-Speech and Text-To-WAV.

JRS

  • Guest
Re: COM
« Reply #44 on: November 14, 2020, 09:30:33 PM »
Charles,

I tried to used SB/DLLC to call the tts.dll library. It gets as far as Begin_Speech and drops to the command prompt.  :(

Here is the C declares.

Code: C
  1. extern int Begin_Speech(DWORD);
  2. extern BOOL Speak_String(int,char *,int,int,int,int,DWORD,int,DWORD,int,DWORD);
  3. extern void End_Speech(void);
  4.  


Code: Script BASIC
  1. ' DLLC SAPI5
  2.  
  3. IMPORT dllc.sbi
  4.  
  5. sapi = dllfile("tts.dll")
  6.  
  7. Begin_Speech = dllproc(sapi, "Begin_Speech i = (i bufsz)")
  8. Speak_String = dllproc(sapi, "Speak_String i = (i usetxt, c *words, i clrbuf, i vidx, i nttsa, i udv, i vol, i udp, i pitch, i uds, i speed)")
  9. End_Speech   = dllproc(sapi, "End_Speech ()")
  10.  
  11. TEXT_BUFFER_SIZE = 5000
  12. USE_TEXT = 1
  13. CLEAR_TEXT_BUFFER = 1
  14. NEW_TTS_ALWAYS = 1
  15. USE_DEFAULT_VOLUME = 1
  16. USE_DEFAULT_PITCH = 1
  17. USE_DEFAULT_SPEED = 1
  18.  
  19. rtn = 0
  20. currentVoice = 0
  21. volume = 0
  22. pitch = 0
  23. speed = 0
  24.  
  25. rtn = dllcall(Begin_Speech, TEXT_BUFFER_SIZE)
  26. PRINT "Begin_Speech = ", rtn,"\n"
  27.  
  28. greeting$ = "Hello World"
  29.  
  30. rtn = dllcall(Speak_String,USE_TEXT,greeting$,CLEAR_TEXTSPEECH_BUFFER,currentVoice,NEW_TTS_ALWAYS,USE_DEFAULT_VOLUME,volume,USE_DEFAULT_PITCH,pitch,USE_DEFAULT_SPEED,speed)
  31. PRINT "Speak_String = ", rtn, "\n"
  32.  
  33. dllcall(End_Speech)
  34.  
  35. dllfile
  36.  
« Last Edit: November 14, 2020, 11:33:32 PM by John »