pythondllcreateobjectwindowserrorcomtypes

Error with python Comtypes CreateObject


I have a C# dll registered on COM which i am trying to use in Python code using comtypes , the code works perfectly fine in the machine i am developing the c# dll but fails to load when deployed in a different machine with all the required files .

Here is the error i am getting

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

and the corresponding python code is

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()

Note that the folder has 3 files ApxWrapper.tlb .APxWrapper.dll and a dependency dll . GetModule works fine and pyton files are generated in comtypes.gen folder Any hints on this highly appreciated

Sanjay


Solution

  • The issue was with the version of .Net dll referenced in both the machine , Python somehow does not give the complete error detail , I was able to make it out by running a sample c# application i wrote and the c# exception thrown had all the necessary info .