def newGetTypeInfo(self,index,lcid=0): from comtypes.automation import IDispatch res = IDispatch._GetTypeInfo_orig(self, index, lcid) if not res: from comtypes import COMError from comtypes.hresult import E_NOTIMPL raise COMError(E_NOTIMPL,None,None) return res
def QueryInterface(self, interface): "Query the object for an interface pointer" # This method is NOT the implementation of # IUnknown::QueryInterface, instead it is supposed to be # called on an COMObject by user code. It allows to get COM # interface pointers from COMObject instances. ptr = self._com_pointers_.get(interface._iid_, None) if ptr is None: raise COMError(E_NOINTERFACE, FormatError(E_NOINTERFACE), (None, None, 0, None, None)) # CopyComPointer(src, dst) calls AddRef! result = POINTER(interface)() CopyComPointer(ptr, byref(result)) return result
def _create_object_from_path (self, clsid, dll_filename, interface=IBaseFilter): iclassfactory = self._raw_guid(IClassFactory._iid_) my_dll = oledll.LoadLibrary(dll_filename) factory_ptr = c_void_p(0) hr = my_dll.DllGetClassObject(self._raw_guid(clsid), iclassfactory, byref(factory_ptr)) if hr!=S_OK: raise COMError(hr, '', '') ptr_icf = POINTER(IClassFactory)(factory_ptr.value) unk = ptr_icf.CreateInstance() # if ScreenCam or SpoutCam is loaded from local file, we also grab its property page if clsid==CLSID_ScreenCam or clsid==CLSID_SpoutCam: factory_ptr = c_void_p(0) hr = my_dll.DllGetClassObject( self._raw_guid(CLSID_SpoutCamPropertyPage if clsid==CLSID_SpoutCam else CLSID_ScreenCamPropertyPage), iclassfactory, byref(factory_ptr)) if hr!=S_OK: raise COMError(hr, '', '') ptr_icf = POINTER(IClassFactory)(factory_ptr.value) unk2 = ptr_icf.CreateInstance() self._page = unk2.QueryInterface(IPropertyPage) return unk.QueryInterface(interface)
def newGetTypeInfo(self,index,lcid=0): res=oldGetTypeInfo(self,index,lcid) if not res: raise COMError(E_NOTIMPL,None,None) return res
def Invoke(self, dispid, *args, **kw): """Invoke a method or property.""" # Memory management in Dispatch::Invoke calls: # http://msdn.microsoft.com/library/en-us/automat/htm/chap5_4x2q.asp # Quote: # The *CALLING* code is responsible for releasing all strings and # objects referred to by rgvarg[ ] or placed in *pVarResult. # # For comtypes this is handled in DISPPARAMS.__del__ and VARIANT.__del__. _invkind = kw.pop("_invkind", 1) # DISPATCH_METHOD _lcid = kw.pop("_lcid", 0) if kw: raise ValueError("named parameters not yet implemented") result = VARIANT() excepinfo = EXCEPINFO() argerr = c_uint() if _invkind in (DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF): # propput array = (VARIANT * len(args))() for i, a in enumerate(args[::-1]): array[i].value = a dp = DISPPARAMS() dp.cArgs = len(args) dp.cNamedArgs = 1 dp.rgvarg = array dp.rgdispidNamedArgs = pointer(DISPID(DISPID_PROPERTYPUT)) else: array = (VARIANT * len(args))() for i, a in enumerate(args[::-1]): array[i].value = a dp = DISPPARAMS() dp.cArgs = len(args) dp.cNamedArgs = 0 dp.rgvarg = array try: self.__com_Invoke(dispid, riid_null, _lcid, _invkind, byref(dp), byref(result), byref(excepinfo), byref(argerr)) except COMError, err: (hresult, text, details) = err.args if hresult == DISP_E_EXCEPTION: details = (excepinfo.bstrDescription, excepinfo.bstrSource, excepinfo.bstrHelpFile, excepinfo.dwHelpContext, excepinfo.scode) raise COMError(hresult, text, details) elif hresult == DISP_E_PARAMNOTFOUND: # MSDN says: You get the error DISP_E_PARAMNOTFOUND # when you try to set a property and you have not # initialized the cNamedArgs and rgdispidNamedArgs # elements of your DISPPARAMS structure. # # So, this looks like a bug. raise COMError(hresult, text, argerr.value) elif hresult == DISP_E_TYPEMISMATCH: # MSDN: One or more of the arguments could not be # coerced. # # Hm, should we raise TypeError, or COMError? raise COMError(hresult, text, ("TypeError: Parameter %s" % (argerr.value + 1), args)) raise