Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

32-Bit COM.DLL -> Surrogate.btm -> 64-Bit COM.DLL

Aug
1,937
71
This is an addendum to my post from April 2019

Reference: Using a 32-bit In-Process COM Server DLL from 64-bit TCC

I've been using a .BTM that I created, which adds DLL Surrogate information to the registry, for 32-bit COM .DLLs that I have created.

Note that before running this .BTM, you must have registered the 32-bit COM .DLL using the 32-bit version of RegSvr32.exe, that is,

%_wow64dir\regsvr32.exe
Code:
:: SURROGATE.BTM
:: Create a DLLSurrogate for each class in a 32-bit COM DLL,
::   so that it can be used from a 64-bit Application (PowerShell, VBScript, etc.)
::
:: This allows me to use my 32-bit COM DLLs,
::   via the SCRIPT command,
::   in 64-bit TCC.EXE
::
:: Reference: https://jpsoft.com/help/script.htm
::
:: 
@setlocal
@echo off

:: Example Usage for the classes in my WIN32API.DLL:
:: surrogate.btm Win32api.Kernel32
:: surrogate.btm Win32api.User32
:: surrogate.btm Win32api.advapi32

iff %# eq 1 then
  Gosub MainProc
else
  echo USAGE: %_batchname ProgID
  echo        %_batchname Win32api.Kernel32
endiff
endlocal
quit

::
:: Main Procedure
::
:MainProc
alias ClsID=`echo %@regquery[HKEY_CLASSES_ROOT\%1\clsid\]`
function ClsID=`%@regquery[HKEY_CLASSES_ROOT\%1\clsid\]`

iff %@ClsID[%1] eq -1 then
  echo %1 is an invalid ProgID
  echo.
  echo Make sure that you registered the 32-bit COM DLL with %_wow64dir\regsvr32.exe
  quit
endiff

echo %@ClsID[%1]

:: @REGxx functions could be used.
:: Instead, I chose to use a .reg script for use with regedit.exe
:: Reference: https://ss64.com/nt/regedit.html
::            https://www.robvanderwoude.com/regedit.php
Gosub RegScript

type surrogate.reg

%_wow64dir\regedit.exe surrogate.reg
Return

::
:: RegScript
::
:RegScript
type <<- endtext > surrogate.reg
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\AppID\%@ClsID[%1]]
"DllSurrogate"=""

[HKEY_CLASSES_ROOT\CLSID\%@ClsID[%1]]
"AppID"="%@ClsID[%1]"
endtext
Return
 
Back
Top