- Aug
- 2,058
- 83
I was looking for an easier way to use COM Objects in TCC, something that would work similar to the VBScript CreateObject, such as follows;
...which returns...
Another example;
...which displays the Run dialog to the user. This method has the same effect as clicking the Start menu and selecting Run.
I came up with the following two .BTMs
To remove the objects;
These .BTMs makes it easier to work with the 64-bit .NET dlls that I create with C#, but are limited to only simple COM calls.
If anyone finds these routines useful, and if they make any changes/additions, please post your improvements.
Joe
Code:
createobject oHebrew System.Globalization.HebrewCalendar
pshell /s "$TheDate = Get-Date"
oHebrew GetYear($TheDate)
...which returns...
Code:
5778
Another example;
Code:
createobject oShell Shell.Application
oShell FileRun()
...which displays the Run dialog to the user. This method has the same effect as clicking the Start menu and selecting Run.
I came up with the following two .BTMs
Code:
:: CreateObject.btm
:: Parameter 1 - User Object Reference
:: Parameter 2 - COM Object name
::
:: Use the pshell command to create a COM object
:: Create a .btm based on the User Object Reference
:: Create an alias for the just created .btm, based on the User Object Reference
::
:: NOTE: If you are using TCC x64, you can only use x64 COM Objects
:: You CAN use a x32 COM Object on TCC x64, but it requires a bit more work
:: Ref: https://jpsoft.com/forums/threads/pshell-use-32-bit-from-64-bit.8469/
::
:: To see what objects have been created;
:: dir %temp\o*.btm
::
:: TODO: More error checking
::
@echo off
iff %_4ver lt 21 then
echo %0 requires TCC Version 21 or later
quit
endiff
pshell /s "$%1 = new-object -com %2"
::
:: Create a .btm called %1
:: Example: if %1 = oMath, create oMath.btm
::
text > %temp\%1.btm
@echo off
pshell /s "$%@name[%0].%$"
endtext
::
:: Create an alias for the just created .btm
::
alias %1=%temp\%1.btm
Code:
:: ReleaseObject.btm
:: Parameter 1 - User Object Reference
::
:: This .btm deletes;
:: - the %1.btm that was created with CreateObject.btm
:: - the %1 alias that was created with CreateObject.btm
::
@echo off
iff exist %temp\%1.btm then
del /q %temp\%1.btm
else
echo %1 Object Reference .btm not found.
endiff
iff isalias %1 then
unalias %1
else
echo %1 Object Reference alias not found.
endiff
:: Uncomment the following if you want to Close the persistent PowerShell interpreter
::pshell /c
To remove the objects;
Code:
ReleaseObject oHebrew
ReleaseObject oShell
These .BTMs makes it easier to work with the 64-bit .NET dlls that I create with C#, but are limited to only simple COM calls.
If anyone finds these routines useful, and if they make any changes/additions, please post your improvements.
Joe