简体   繁体   中英

How to Instantiate a 64-bit Class from 32-bit Excel Process

I have registered several DLLs specific to Unicom Dimensions / IBM SPSS Data Collection Desktop 7 (x64) software and verify the Classes are showing up under HKCR/Classes as well as HKLM.

在此处输入图像描述

Dumpbin.exe indicates the following dependencies, , I don't see anything that looks out of sorts here, ie, nothing that's specific to the Unicom software that might not have been registered etc.

Image has the following dependencies

KERNEL32.dll
USER32.dll
GDI32.dll
COMDLG32.dll
ADVAPI32.dll
ole32.dll
OLEAUT32.dll
ATL100.DLL
SHLWAPI.dll
MSVCP100.dll
MSVCR100.dll

But when trying to instantiate from VBA (Excel 2016, 32b) it fails with a 429, ActiveX can't create Object :

Dim exp as Object
Set exp = CreateObject("ExportExcel.Export")

I can instantiate from python (64b 3.7):

from win32com import client
exp = client.Dispatch("ExportExcel.Export")

Is this as simple as having 32b Excel and 64b Dimensions? Could I solve this via 64b Excel installation?

Unicom's documentation indicates that this is the proper way to instantiate the class (the example uses early binding, I've tried both to no avail).

' ---- Export the Tables ----
    Dim MYEXPORT As ExportExcelLib.Export
    Set MYEXPORT = New ExportExcelLib.Export
    Export MYEXPORT, TableXml, PropertyXml

Further, Unicom provides its own "mrScriptBasic" language which is based on Visual Basic. As you might expect, they also use a CreateObject function to instantiate classes. Within their scripting software, this function works as expected and returns a proper instance of the class.

Update

I've attempted to force it through dllhost as Noodles mentions in comments. I've run the.bat as an administrator:

REM _Enable.bat
REM This file merges reg_script.reg using the Reg.exe command.
REM This allows 32b program to call a 64b dll via surrogate
REM It is a per user setting but Regedit doesn't allow non admins to run it
reg import "reg_script.reg"
Pause

And this imports the reg_script.reg file as follows:

Windows Registry Editor Version 5.00
;reg_script.reg
[HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID\{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}]
@="ExportExcel"
"AppID"="{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Wow6432Node\AppID\{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}]
"DllSurrogate"=""

[HKEY_CURRENT_USER\SOFTWARE\Classes\AppID\{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}]
"DllSurrogate"=""

Error persists whether I attempt to use the class name or GUID.

I had the same problem and it was solved using solution described in following web page: https://techtalk.gfi.com/32bit-object-64bit-environment/

In case of un-availablity of web page, I copy its main paragraph here:

To do this, it involves a small number of simple registry hacks:

  • Locate your COM object GUID under the HKey_Classes_Root\Wow6432Node\CLSID[GUID]

  • Once located add a new REG_SZ (string) Value. Name should be AppID and data should be the same COM object GUID you have just searched for

  • Add a new key under HKey_Classes_Root\Wow6432Node\AppID\ The new key should be called the same as the com object GUID

  • Under the new key you just added, add a new REG_SZ (string) Value, and call it DllSurrogate. Leave the value empty

  • Create a new Key under HKey_Local_Machine\Software\Classes\AppID\ Again the new key should be called the same as the COM object's GUID. No values are necessary to be added under this key.

That's it, your COM Object should now be accessible from a 64bit environment and can be used like a regular COM Object.

Windows Registry Editor Version 5.00
;reg_script.reg
[HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID\{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}]
"AppID"="{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Wow6432Node\CLSID\{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}]
"AppID"="{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Wow6432Node\AppID\{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}]
"DllSurrogate"=""

[HKEY_CURRENT_USER\SOFTWARE\Classes\AppID\{AE2E32FA-FB29-4C42-BFF9-7ACFA1AB0A1B}]
"DllSurrogate"=""

If the GUID is right .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM