简体   繁体   中英

Using COM object in Python with win32com

I'm trying to dispatch a class called Signal from a COM library using win32com.client. Unfortunately, I got an error of invalid class string. 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 with its IID and interface can be found among other classes.

Is it possible to instantiate this class in python using win32client similar as VBA does it?

I've tried to dispatch the class by its IID but with no success. The only classes that I can access are those listed in the windows registry editor.

I know that the description of the problem might be very vague, but I hope it's well know issue and I'm missing some basics here.

After spending some time on it, I've finally found out what is the issue. 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. With help of OLE/COM Object Viewer I found that this class has attribute [noncreatable], so it cannot be instantiated by itself. You cannot create a new object of this class at the top level—that is, by calling CreateInstance or CoCreateInstance, which win32com.clinet.Dispatch is doing. Instantiation of an object of this class requires a method call to another object. I instantiated another object from the same library and run one of its methods that returns an interface to the class I needed. Having pointer to ISignal is then easy to use all of its methods.

Thanks

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