【发布时间】:2020-10-30 08:37:12
【问题描述】:
我在 COM 上注册了一个 C# dll,我尝试使用 comtypes 在 Python 代码中使用该代码,该代码在我正在开发 c# dll 的机器上工作得非常好,但在部署到具有所有所需文件。
这是我遇到的错误
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\bellagio\DriverManager\audiotest\apx525\apx525_Wrapper.py", line 257, in <module>
c._Connect()
File "C:\Python27\Lib\site-packages\bellagio\DriverManager\audiotest\apx525\apx525_Wrapper.py", line 51, in _Connect
self.apx525 = CreateObject("APxWrapper.APxWrapper",None,None,apx.IAPxWrapper)
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 235, in CreateObject
obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
File "C:\Python27\lib\site-packages\comtypes\__init__.py", line 1145, in CoCreateInstance
_ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
File "_ctypes/callproc.c", line 936, in GetResult
WindowsError: [Error -2147024894] The system cannot find the file specified
对应的python代码是
try:
from comtypes.client import CreateObject,GetModule, Constants, GetEvents
from comtypes import COMError
GetModule("P:\\Share\\Test\\TestBed\\Bellagio\\dll\\APxWrapper.tlb")
from comtypes.gen import APxWrapper as apx
except:
tblog.warnLog("Need to install comtypes package, AP driver not imported")
class IAPxWrapper_Impl(object):
def __init__(self):
self.apx525 = None
self.activeSignalPath = ''
self.activeMeasurement = ''
def _Connect(self):
self.apx525 = CreateObject("APxWrapper.APxWrapper",None,None,apx.IAPxWrapper)
self.apx525._GUIVisible = True;
return True
c = IAPxWrapper_Impl()
c._Connect()
请注意,该文件夹有 3 个文件 ApxWrapper.tlb .APxWrapper.dll 和一个依赖项 dll 。 GetModule 工作正常,pyton 文件在 comtypes.gen 文件夹中生成 对此高度赞赏的任何提示
桑杰
【问题讨论】:
标签: python dll createobject windowserror comtypes