64 位 python 正在构建一个 32 位 COM 服务器:(

问题描述

import platform 
platform.architecture() #('64bit','WindowsPE')

我在 64 位上运行,特别是:

Python 3.8.8 (default,Apr 13 2021,15:08:03) [MSC v.1916 64 bit (AMD64)] :: Anaconda,Inc. on win32

我已经创建了一个非常基本的 COM 服务器,我想从 64 位客户端调用它:

class HelloWorld:
    # pythoncom.CreateGuid()
    _reg_clsid_ = "{E32B2663-BD8C-472A-AC96-142AE4665FD7}"
    _reg_desc_ = "MyLib COM server"
    _reg_progid_ = "MyLib.HelloWorld"

    _public_methods_ = ["Hello"]
    _public_attrs_ = ["softspace","noCalls"]
    _readonly_attrs_ = ["noCalls"]

    def __init__(self):
        self.softspace = 1
        self.noCalls = 0

    def Hello(self,who):
        self.noCalls = self.noCalls + 1
        # insert "softspace" number of spaces
        return "Hello" + " " * self.softspace + str(who)

if __name__ == '__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine(HelloWorld)

注册使用:python server.py -(调用__main__方法注册服务器)

但是从 64 位 COM 客户端 (Excel VBA),我无法创建实例

Sub t()
    Dim a As Object
    Set a = CreateObject("MyLib.HelloWorld")
End Sub

即使我可以在 python 64 位

from comtypes.client import CreateObject
c = CreateObject('MyLib.HelloWorld')

并且可以在 32 位 VBA 主机中。所以我猜我的 python 服务器被声明为 32 位,python comtypes 只是有效TM,无论服务器位数如何,但我在 Excel 64 中收到 Module not found 错误位(32 位工作正常)。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)