[ pywin32-Bugs-2726657 ] getting PyIUnknown for a known return typeâ
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2009-04-14 03:06:49
|
Bugs item #2726657, was opened at 2009-04-02 14:01 Message generated for change (Comment added) made by kpoman You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2726657&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: com Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Patricio Stegmann (kpoman) Assigned to: Nobody/Anonymous (nobody) Summary: getting PyIUnknown for a known return type Initial Comment: Hello all, I am getting a strange behaviour for a generated clsid: class IAcquisitionDevice(DispatchBaseClass): # SOME CODE STRIPPED HERE # Result is of type IAcquisitionDeviceInfo def EnumerateDevices(self): return self._ApplyTypes_(1610743823, 1, (8201, 0), (), u'EnumerateDevices', '{7ED03FE9-4DCC-4F5D-BDF8-4D4D22C1FA10}',) def GetNumberOfDevices(self): return self._oleobj_.InvokeTypes(1610743822, LCID, 1, (3, 0), (),) # SOME CODE STRIPPED HERE # THEN SOME LINES LATER class IAcquisitionDeviceInfo(DispatchBaseClass): CLSID = IID('{7ED03FE9-4DCC-4F5D-BDF8-4D4D22C1FA10}') coclass_clsid = IID('{DDD89560-8B0E-4D6F-9BDF-7E14068C1DEB}') _prop_map_get_ = { "Properties": (1610743809, 2, (8, 0), (), "Properties", None), "SerialNumber": (1610743808, 2, (8, 0), (), "SerialNumber", None), } _prop_map_put_ = { } I saved all this on a mk4 file. Then I perform some tests: >>> import mk4 >>> dev = mk4.AcquisitionDevice() >>> print dev.GetNumberOfDevices() 1 >>> print dev.EnumerateDevices() (<PyIUnknown at 0x00BCB4C0 with obj at 0x0509FF90>,) >>> I dont know why I am getting a PyIUnknown if it should now I am returning IAcquisitionDevice object ! I guess there is some error somewhere and I really need to fix it. From that ActiveX documentation I see this: void EnumerateDevices (AcquisitionDeviceInfo infos[]) enumerate all connected acquisition devices So it should return an array of infos and not only one info (this array contains infos for all the different compatible devices). So somehow the python cache file got wrongly generated. How can I fix this please ? How to declare it should be an array of deviceinfos instead of a single deviceinfo ? Thank you all for any help, Patricio ---------------------------------------------------------------------- >Comment By: Patricio Stegmann (kpoman) Date: 2009-04-14 05:06 Message: Mark, thanks for your help ! I didnt see your response until today (just saw comment 1). The function should return some kind of enumeration, it says this in the documentation: void EnumerateDevices (AcquisitionDeviceInfo infos[]) enumerate all connected acquisition devices I just did some tests: >>> import mk4 >>> dev = mk4.AcquisitionDevice() >>> print dev.EnumerateDevices() (<PyIUnknown at 0x00C11330 with obj at 0x04C90010>,) >>> print dev.GetDescriptor() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mk4.py", line 121, in GetDescriptor ret = self._oleobj_.InvokeTypes(1610743824, LCID, 1, (9, 0), ((8, 1),),deviceSerialNumber pywintypes.com_error: (-2147024809, 'El par\xe1metro no es correcto.', None, None) >>> print dev.GetDescriptor('') <win32com.gen_py.Sagem SÚcuritÚ MorphoKit SDK.IAcquisitionDeviceDescriptor instance at 0x12810360> >>> So GetDescriptor is working as expected, an IAcquisitionDeviceDescriptor. But EnumerateDevices is giving some list-like object, composed of PyIUnknown objects. I tried putting an __init__ into the class IAcquisitionDeviceInfo but nothing got printed. Is it returned as a list of PyIUnknown because the generated com wrapper (via makepy) did explictly said that it should return a DeviceInfo and not a list of DeviceInfo's then win32com got cheated by itself ? Is there a way to declare/update on the generated that it should return a collection of DeviceInfos and thus have it detect it as a collection and cast it correctly ? Is there a way to cast manually to AcquisitionDeviceInfo ? Doing the following fails: >>> from pywintypes import IID >>> devinfo = dev.EnumerateDevices()[0] >>> print devinfo <PyIUnknown at 0x00C11480 with obj at 0x04C9FFB0> >>> devinfo.QueryInterface(IID('{7ED03FE9-4DCC-4F5D-BDF8-4D4D22C1FA10}')) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: There is no interface object registered that supports this IID >>> Is there a way to view if there is some error on the activex itself ? Some free tool to check on the assembly what it is supposed to return ? Because there could be a bug in the activex itself. FYI it was generated from this command: regasm /tlb /codebase Sagem.MorphoKit.dll Please let me know how I can debug this ! ---------------------------------------------------------------------- Comment By: Mark Hammond (mhammond) Date: 2009-04-06 13:58 Message: Do you have any information about the API exposed by this object. Looking at: # Result is of type IAcquisitionDeviceInfo def EnumerateDevices(self): return self._ApplyTypes_(1610743823, 1, (8201, 0), (), u'EnumerateDevices', '{7ED03FE9-4DCC-4F5D-BDF8-4D4D22C1FA10}',) It seems something (maybe pywin32, maybe the object) is confused about the enumeration. A function named 'EnumerateDevices' would be expected to return a list/enum of IAcquisitionDeviceInfo's, not an IAcquisitionDeviceInfo directly, and I suspect this is the root of the problem. To confirm, adding a print to the __init__ of IAcquisitionDeviceInfo might tell you if we are trying to create such an object, but failing (presumably as we have an enum) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2726657&group_id=78018 |