- Aug
- 2,134
- 92
This is by no means a finished batch file, but it is a start to a solution in which I can access COM Objects from the TCC CLI. Source code for COMCALL.BTM is below the Q&A.
Questions with Answers
Q. Where exactly can I get these "COM Objects" to install on my system?
A. Your system already has quite a few COM Objects on it.
To display a complete list of Registered Objects on your Windows System, refer to this forum message;
[title]
Q. Okay, I've got a list of the Registered Objects that are on my system. How do I find out the methods for a specific COM Object?
A. To list the methods for an ActiveX (COM) Object, refer to this forum message;
[title]
Q. How about an example of what COMCALL.BTM can do?
A. Let's say that you wanted to do something similar as the TCC @GETFOLDER Function does.
Q. Where did you get that "Folder BrowseForFolder (int, string, int, Variant)" line, and what is it for?
A. I used methodlist.btm as follows;
A list of the methods was returned. Using my mouse, I copied the definition for BrowseForFolder to the clipboard, and pasted it into the command line.
Q. Why do I need "Folder BrowseForFolder (int, string, int, Variant)"?
A. It allows the batch file to determine the name of the method, and the number and type of arguments for the method.
Q. Why do you need to use CScript.exe with this batch file?
A. TCC does not have the ability to call COM Objects, but CScript.exe does.
Q. Why do you need to use PowerShell.exe with COMLIST.BTM and METHODLIST.BTM?
A. TCC does not have the ability to call COM Objects, but PowerShell.exe does.
Q. Why did you not just use CScript.exe with COMLIST.BTM and METHODLIST.BTM?
A. The only way I could figure out how to do the same thing with CScript.exe would have required each system to have the TLBINF32.dll file installed on everyone's system.
TLBINF32.dll came with my copy of Visual Sudio 6.0, and I cannot find if it is legal to distribute it.
I hope that others find this batch file useful. For me, I can now call from the TCC CLI all of the functions in the Visual Basic 6.0 COM Objects that I created over the years. I have been calling my COM Objects from VBScript, PowerShell, AutoIt, PowerBASIC, and now, I can call them from TCC, without having to re-create the functions in TCC.
Joe
Questions with Answers
Q. Where exactly can I get these "COM Objects" to install on my system?
A. Your system already has quite a few COM Objects on it.
To display a complete list of Registered Objects on your Windows System, refer to this forum message;
[title]
Q. Okay, I've got a list of the Registered Objects that are on my system. How do I find out the methods for a specific COM Object?
A. To list the methods for an ActiveX (COM) Object, refer to this forum message;
[title]
Q. How about an example of what COMCALL.BTM can do?
A. Let's say that you wanted to do something similar as the TCC @GETFOLDER Function does.
Code:
comcall shell.application "Folder BrowseForFolder (int, string, int, Variant)" 0, "Example", 0, "36"
Q. Where did you get that "Folder BrowseForFolder (int, string, int, Variant)" line, and what is it for?
A. I used methodlist.btm as follows;
Code:
methodlist.btm shell.application
A list of the methods was returned. Using my mouse, I copied the definition for BrowseForFolder to the clipboard, and pasted it into the command line.
Q. Why do I need "Folder BrowseForFolder (int, string, int, Variant)"?
A. It allows the batch file to determine the name of the method, and the number and type of arguments for the method.
Q. Why do you need to use CScript.exe with this batch file?
A. TCC does not have the ability to call COM Objects, but CScript.exe does.
Q. Why do you need to use PowerShell.exe with COMLIST.BTM and METHODLIST.BTM?
A. TCC does not have the ability to call COM Objects, but PowerShell.exe does.
Q. Why did you not just use CScript.exe with COMLIST.BTM and METHODLIST.BTM?
A. The only way I could figure out how to do the same thing with CScript.exe would have required each system to have the TLBINF32.dll file installed on everyone's system.
TLBINF32.dll came with my copy of Visual Sudio 6.0, and I cannot find if it is legal to distribute it.
I hope that others find this batch file useful. For me, I can now call from the TCC CLI all of the functions in the Visual Basic 6.0 COM Objects that I created over the years. I have been calling my COM Objects from VBScript, PowerShell, AutoIt, PowerBASIC, and now, I can call them from TCC, without having to re-create the functions in TCC.
Joe
Code:
::--------------------------------------------------------------------
:: comcall.BTM
::
:: Call Methods from ActiveX (COM) Objects from the CLI
::
:: TCC 15.01.52
:: 2013/08/05
:: Joe Caverly
::
:: I am working on a TCC Plugin to accomplish this same task, and am
:: using this as an example of what I want to accomplish.
::
:: The plugin version will be a function (@comcall)
:: and a command (comcall).
::
:: This batch file requires cscript.exe in order to work properly.
::
:: TODO: Error checking of command line arguments, misc. stuff.
:: Error checking in the .vbs script that this batch file creates.
::--------------------------------------------------------------------
@setlocal
@echo off
:: For debugging purposes, verbose=1
:: For non-debugging purposes, verbose=0
set verbose=0
set BatchParameters=%#
if %verbose=1 echo Batch Parameters=%BatchParameters
set dispatch=%1
set Definition=%2
iff %BatchParameters lt 2 then
echo USAGE: comcall dispatch "Definition"
echo comcall dispatch "Definition" argument(s)
echo.
echo Exple: comcall shell.application "void MinimizeAll ()"
echo comcall shell.application "void ControlPanelItem (string)" "desk.cpl"
echo.
echo comcall shell.application "Folder BrowseForFolder (int, string, int, Variant)" 0, "Example", 0, "36"
echo.
echo comcall shell.application "void FileRun ()"
echo.
echo The following calls a COM Object that I created with Visual Basic 6.0;
echo comcall jlcutils.clsmath "Variant ppp (Variant)" 6.59
goto eoj
endiff
if exist %@path[%_batchname]comcall.vbs del %@path[%_batchname]comcall.vbs > nul
::
:: Method return type
::
set MethodReturnType=%@word[0,%@unquote[%Definition]]
::
:: Method name
::
set MethodName=%@word[1,%@unquote[%Definition]]
::
:: How many left parentheses in the "Definition"
::
set LParenthCount=%@count[(,%Definition]
iff %LParenthCount ne 1 then
echo Error In Definition
echo %Definition
goto eoj
else
if %verbose=1 echo Found 1 left parentheses
endiff
::
:: How many right parentheses in the "Definition"
::
set RParenthCount=%@count[),%Definition]
iff %RParenthCount ne 1 then
echo Error In Definition
echo %Definition
goto eoj
else
if %verbose=1 echo Found 1 right parentheses
endiff
::
:: Where does the beginning parentheses begin?
::
set BParenth=%@index[%2,(]
::
:: Where does the ending parentheses begin?
::
set EParenth=%@index[%2,)]
::
:: Make sure left is before right parentheses
::
iff %BParenth gt %EParenth then
echo Definition contains )(, should be ()
goto eoj
else
if %verbose=1 echo Definition contains (), okay to continue
endiff
::
:: Get the definition without the parentheses
::
set defLength=%@eval[(%EParenth-%BParenth)-1]
set Definition=%@instr[%@eval[%BParenth+1],%defLength,%Definition]
if %verbose=1 echo Definition without parentheses=%Definition
::
:: How many arguments does the definition have?
::
iff %@eval[%BParenth+1] eq %EParenth then
set defArgc=0
if %verbose=1 echo No Arguments
else
set defArgc=%@words[,%Definition]
if %verbose=1 echo Definition has %defArgc argument(s)
endiff
::
:: We already know that we have two Batch Parameters,
:: the %dispatch (first) and the %Definition (second)
:: The %defArgc + 2 should equal %BatchParameters
::
if %verbose=1 echo defArgc + 2 = %@eval[%defArgc + 2]
if %verbose=1 echo BatchParameters=%BatchParameters
iff %@eval[%defArgc + 2] le %BatchParameters then
if %verbose=1 echo Everything is okay to proceed
else
echo %defArgc arguments are required for the definition (%Definition)
goto eoj
endiff
switch %defArgc
case 0
gosub 0args
case 1
set Arg1=%3
gosub 1args
case 2
set Arg1=%3
set Arg2=%4
gosub 2args
case 3
set Arg1=%3
set Arg2=%4
set Arg3=%5
gosub 3args
case 4
set Arg1=%3
set Arg2=%4
set Arg3=%5
set Arg4=%6
gosub 4args
default
echo You have a definition with more than 4 arguments.
echo Feel free to expand this batch file to accomodate your requirments.
goto eoj
endswitch
do i = %start to %end
echo %@line[%_batchname,%i] >> %@path[%_batchname]comcall.vbs
enddo
if %verbose=1 type comcall.vbs
cscript //nologo %@path[%_batchname]comcall.vbs
:eoj
if exist %@path[%_batchname]comcall.vbs del %@path[%_batchname]comcall.vbs > nul
endlocal
quit
:0args
set start=%@eval[%_batchline+1]
text > nul
set dispatch = wscript.createobject("%dispatch")
wscript.echo dispatch.%MethodName()
endtext
set end=%@eval[%_batchline-3]
return
:1args
set start=%@eval[%_batchline+1]
text > nul
set dispatch = wscript.createobject("%dispatch")
wscript.echo dispatch.%MethodName(%Arg1)
endtext
set end=%@eval[%_batchline-3]
return
:2args
set start=%@eval[%_batchline+1]
text > nul
set dispatch = wscript.createobject("%dispatch")
wscript.echo dispatch.%MethodName(%Arg1, %Arg2)
endtext
set end=%@eval[%_batchline-3]
return
:3args
set start=%@eval[%_batchline+1]
text > nul
set dispatch = wscript.createobject("%dispatch")
wscript.echo dispatch.%MethodName(%Arg1, %Arg2, %Arg3)
endtext
set end=%@eval[%_batchline-3]
return
:4args
set start=%@eval[%_batchline+1]
text > nul
set dispatch = wscript.createobject("%dispatch")
wscript.echo dispatch.%MethodName(%Arg1, %Arg2, %Arg3, %Arg4)
endtext
set end=%@eval[%_batchline-3]
return