繁体   English   中英

在 Python 中使用 COM object 与 win32com

[英]Using COM object in Python with win32com

我正在尝试使用 win32com.client 从 COM 库中调度一个名为 Signal 的 class。 不幸的是,我收到了无效 class 字符串的错误。 The COM library is registered and when referenced in Visual Basic for Application the class Signal is visible and can be instantiated VBA Signal class However, the class in not listed explicitly in Register Editor Windows Register Editor When recompiling the COM library with make.py the class可以在其他类中找到其 IID 和接口。

是否可以使用类似于 VBA 的 win32client 在 python 中实例化此 class 吗?

我尝试通过 IID 发送 class 但没有成功。 我可以访问的唯一类是 windows 注册表编辑器中列出的类。

我知道问题的描述可能非常模糊,但我希望这是众所周知的问题,我在这里缺少一些基础知识。

在花了一些时间之后,我终于发现了问题所在。 The class Signal that I was trying to instantiate is not register neither in x86 nor x64 windows registry, this is one thing, and this made me to dig into details of the class definition. 在 OLE/COM Object Viewer 的帮助下,我发现这个 class 具有属性 [noncreatable],因此它不能自行实例化。 您不能在顶层创建此 class 的新 object,即通过调用 Win32com.clinet.Dispatch 正在执行的 CreateInstance 或 CoCreateInstance。 此 class 的 object 的实例化需要对另一个 object 的方法调用。 我从同一个库中实例化了另一个 object 并运行其中一个方法,该方法返回到我需要的 class 的接口。 拥有指向 ISignal 的指针就很容易使用它的所有方法。

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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