class IMMDevice(IUnknown): _iid_ = GUID('{D666063F-1587-4E43-81F1-B948E807363F}') _methods_ = [ COMMETHOD([], HRESULT, 'Activate', (['in'], POINTER(GUID), 'iid'), (['in'], DWORD, 'dwClsCtx'), (['in'], POINTER(DWORD), 'pActivationParans'), (['out', 'retval'], POINTER( POINTER(IAudioEndpointVolume)), 'ppInterface')), STDMETHOD(HRESULT, 'OpenPropertyStore', []), STDMETHOD(HRESULT, 'GetId', []), STDMETHOD(HRESULT, 'GetState', []) ]
class IAudioEndpointVolume(IUnknown): _iid_ = GUID('{5CDF2C82-841E-4546-9722-0CF74078229A}') _methods_ = [ STDMETHOD(HRESULT, 'RegisterControlChangeNotify', []), STDMETHOD(HRESULT, 'UnregisterControlChangeNotify', []), STDMETHOD(HRESULT, 'GetChannelCount', []), COMMETHOD([], HRESULT, 'SetMasterVolumeLevel', (['in'], c_float, 'fLevelDB'), (['in'], POINTER(GUID), 'pguidEventContext')), COMMETHOD([], HRESULT, 'SetMasterVolumeLevelScalar', (['in'], c_float, 'fLevelDB'), (['in'], POINTER(GUID), 'pguidEventContext')), COMMETHOD([], HRESULT, 'GetMasterVolumeLevel', (['out', 'retval'], POINTER(c_float), 'pfLevelDB')), COMMETHOD([], HRESULT, 'GetMasterVolumeLevelScalar', (['out', 'retval'], POINTER(c_float), 'pfLevelDB')), COMMETHOD([], HRESULT, 'SetChannelVolumeLevel', (['in'], DWORD, 'nChannel'), (['in'], c_float, 'fLevelDB'), (['in'], POINTER(GUID), 'pguidEventContext')), COMMETHOD([], HRESULT, 'SetChannelVolumeLevelScalar', (['in'], DWORD, 'nChannel'), (['in'], c_float, 'fLevelDB'), (['in'], POINTER(GUID), 'pguidEventContext')), COMMETHOD([], HRESULT, 'GetChannelVolumeLevel', (['in'], DWORD, 'nChannel'), (['out', 'retval'], POINTER(c_float), 'pfLevelDB')), COMMETHOD([], HRESULT, 'GetChannelVolumeLevelScalar', (['in'], DWORD, 'nChannel'), (['out', 'retval'], POINTER(c_float), 'pfLevelDB')), COMMETHOD([], HRESULT, 'SetMute', (['in'], BOOL, 'bMute'), (['in'], POINTER(GUID), 'pguidEventContext')), COMMETHOD([], HRESULT, 'GetMute', (['out', 'retval'], POINTER(BOOL), 'pbMute')), COMMETHOD( [], HRESULT, 'GetVolumeStepInfo', (['out', 'retval'], POINTER(c_float), 'pnStep'), (['out', 'retval'], POINTER(c_float), 'pnStepCount'), ), COMMETHOD([], HRESULT, 'VolumeStepUp', (['in'], POINTER(GUID), 'pguidEventContext')), COMMETHOD([], HRESULT, 'VolumeStepDown', (['in'], POINTER(GUID), 'pguidEventContext')), COMMETHOD( [], HRESULT, 'QueryHardwareSupport', (['out', 'retval'], POINTER(DWORD), 'pdwHardwareSupportMask')), COMMETHOD([], HRESULT, 'GetVolumeRange', (['out', 'retval'], POINTER(c_float), 'pfMin'), (['out', 'retval'], POINTER(c_float), 'pfMax'), (['out', 'retval'], POINTER(c_float), 'pfIncr')), ]
class IGlobalInterfaceTable(IUnknown): _iid_ = GUID("{00000146-0000-0000-C000-000000000046}") _methods_ = [ STDMETHOD(HRESULT, "RegisterInterfaceInGlobal", [POINTER(IUnknown), POINTER(GUID), POINTER(DWORD)]), STDMETHOD(HRESULT, "RevokeInterfaceFromGlobal", [DWORD]), STDMETHOD(HRESULT, "GetInterfaceFromGlobal", [DWORD, POINTER(GUID), POINTER(POINTER(IUnknown))]), ] def RegisterInterfaceInGlobal(self, obj, interface=IUnknown): cookie = DWORD() self.__com_RegisterInterfaceInGlobal(obj, interface._iid_, cookie) return cookie.value def GetInterfaceFromGlobal(self, cookie, interface=IUnknown): ptr = POINTER(interface)() self.__com_GetInterfaceFromGlobal(cookie, interface._iid_, ptr) return ptr def RevokeInterfaceFromGlobal(self, cookie): self.__com_RevokeInterfaceFromGlobal(cookie)
def test_derived(self): # XXX leaks 50 refs self.assertEqual(method_count(IUnknown), 3) class IMyInterface(IUnknown): pass self.assertEqual(method_count(IMyInterface), 3) # assigning _methods_ does not work until we have an _iid_! self.assertRaises(AttributeError, setattr, IMyInterface, "_methods_", []) IMyInterface._iid_ = GUID.create_new() IMyInterface._methods_ = [] self.assertEqual(method_count(IMyInterface), 3) IMyInterface._methods_ = [STDMETHOD(HRESULT, "Blah", [])] self.assertEqual(method_count(IMyInterface), 4)
class tagARRAYDESC(Structure): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 594 pass ################################################################ # interface vtbl definitions ICreateTypeLib._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 2149 COMMETHOD([], HRESULT, 'CreateTypeInfo', (['in'], LPOLESTR, 'szName'), (['in'], TYPEKIND, 'tkind'), (['out'], POINTER(POINTER(ICreateTypeInfo)), 'ppCTInfo')), STDMETHOD(HRESULT, 'SetName', [LPOLESTR]), STDMETHOD(HRESULT, 'SetVersion', [WORD, WORD]), STDMETHOD(HRESULT, 'SetGuid', [POINTER(GUID)]), STDMETHOD(HRESULT, 'SetDocString', [LPOLESTR]), STDMETHOD(HRESULT, 'SetHelpFileName', [LPOLESTR]), STDMETHOD(HRESULT, 'SetHelpContext', [DWORD]), STDMETHOD(HRESULT, 'SetLcid', [LCID]), STDMETHOD(HRESULT, 'SetLibFlags', [UINT]), STDMETHOD(HRESULT, 'SaveAllChanges', []), ] ICreateTypeLib2._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 2444 STDMETHOD(HRESULT, 'DeleteTypeInfo', [POINTER(ITypeInfo)]), STDMETHOD(HRESULT, 'SetCustData', [POINTER(GUID), POINTER(VARIANT)]),
class IDispatch(IUnknown): _iid_ = GUID("{00020400-0000-0000-C000-000000000046}") _methods_ = [ COMMETHOD([], HRESULT, 'GetTypeInfoCount', (['out'], POINTER(UINT))), COMMETHOD( [], HRESULT, 'GetTypeInfo', (['in'], UINT, 'index'), (['in'], LCID, 'lcid', 0), ## Normally, we would declare this parameter in this way: ## (['out'], POINTER(POINTER(ITypeInfo)) ) ), ## but we cannot import comtypes.typeinfo at the top level (recursive imports!). (['out'], POINTER(POINTER(IUnknown)))), STDMETHOD( HRESULT, 'GetIDsOfNames', [POINTER(IID), POINTER(c_wchar_p), UINT, LCID, POINTER(DISPID)]), STDMETHOD(HRESULT, 'Invoke', [ DISPID, POINTER(IID), LCID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT) ]), ] def GetTypeInfo(self, index, lcid=0): """Return type information. Index 0 specifies typeinfo for IDispatch""" import comtypes.typeinfo result = self._GetTypeInfo(index, lcid) return result.QueryInterface(comtypes.typeinfo.ITypeInfo) def GetIDsOfNames(self, *names, **kw): """Map string names to integer ids.""" lcid = kw.pop("lcid", 0) assert not kw arr = (c_wchar_p * len(names))(*names) ids = (DISPID * len(names))() self.__com_GetIDsOfNames(riid_null, arr, len(names), lcid, ids) return ids[:] def _invoke(self, memid, invkind, lcid, *args): var = VARIANT() argerr = c_uint() dp = DISPPARAMS() if args: array = (VARIANT * len(args))() for i, a in enumerate(args[::-1]): array[i].value = a dp.cArgs = len(args) if invkind in (DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF): dp.cNamedArgs = 1 dp.rgdispidNamedArgs = pointer(DISPID(DISPID_PROPERTYPUT)) dp.rgvarg = array self.__com_Invoke(memid, riid_null, lcid, invkind, dp, var, None, argerr) return var._get_value(dynamic=True) 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 return result._get_value(dynamic=True)
#from comtypes.connectionpoints import dispinterface_EventReceiver class IDocHostUIHandler(IUnknown): _iid_ = GUID("{BD3F23C0-D43E-11CF-893B-00AA00BDCE1A}") ##CTYPES, maybe the following 2 ifaces should be in ctypes? class IOleCommandTarget(IUnknown): _iid_ = GUID("{B722BCCB-4E68-101B-A2BC-00AA00404770}") class IOleInPlaceFrame(IUnknown): _iid_ = GUID("{00000116-0000-0000-C000-000000000046}") ##CTYPES, change default behaviour for addreffing iface pointers on ##methods that are not implemented on python side so that __del__ does IDocHostUIHandler._methods_ = IUnknown._methods_ + [ STDMETHOD(HRESULT, "ShowContextMenu", [DWORD, DWORD, DWORD, DWORD]), STDMETHOD(HRESULT, "GetHostInfo", [DWORD]), #TODO wrap DOCHOSTUIINFO struct STDMETHOD(HRESULT, "ShowUI", [DWORD, DWORD, DWORD, DWORD, DWORD]), STDMETHOD(HRESULT, "HideUI", []), STDMETHOD(HRESULT, "UpdateUI", []), STDMETHOD(HRESULT, "EnableModeless", [BOOL]), STDMETHOD(HRESULT, "OnDocWindowActivate", [BOOL]), STDMETHOD(HRESULT, "OnFrameWindowActivate", [BOOL]), STDMETHOD(HRESULT, "ResizeBorder", [DWORD, DWORD, BOOL]), STDMETHOD(HRESULT, "TranslateAccelerator", [POINTER(MSG), POINTER(GUID), DWORD]), STDMETHOD(HRESULT, "GetOptionKeyPath", [DWORD, DWORD]), STDMETHOD(HRESULT, "GetDropTarget", [DWORD, DWORD]), STDMETHOD(HRESULT, "GetExternal", [POINTER(POINTER(IDispatch))]), STDMETHOD(HRESULT, "TranslateUrl", [DWORD, DWORD, DWORD]), STDMETHOD(HRESULT, "FilterDataObject", [WORD, DWORD]), ]
DV_E_DVASPECT = 0x8004006B DV_E_DVTARGETDEVICE_SIZE = 0x8004006C DV_E_NOIVIEWOBJECT = 0x8004006D DROPEFFECT_NONE = 0 DROPEFFECT_COPY = 1 DROPEFFECT_MOVE = 2 DROPEFFECT_LINK = 4 DROPEFFECT_SCROLL = 0x80000000 DRAGDROP_S_DROP = 0x00040100 DRAGDROP_S_CANCEL = 0x00040101 DRAGDROP_S_USEDEFAULTCURSORS = 0x00040102 IDataObject._methods_ = IUnknown._methods_ + [ STDMETHOD(HRESULT, "GetData", [POINTER(FORMATETC), POINTER(STGMEDIUM)]), STDMETHOD(HRESULT, "GetDataHere", [POINTER(FORMATETC), POINTER(STGMEDIUM)]), STDMETHOD(HRESULT, "QueryGetData", [POINTER(FORMATETC)]), STDMETHOD(HRESULT, "GetCanonicalFormatEtc", [POINTER(FORMATETC), POINTER(FORMATETC)]), STDMETHOD( HRESULT, "SetData", [POINTER(FORMATETC), POINTER(STGMEDIUM), BOOL]), STDMETHOD(HRESULT, "EnumFormatEtc", [DWORD, POINTER(POINTER(IEnumFORMATETC))]), STDMETHOD( HRESULT, "DAdvise", [POINTER(FORMATETC), DWORD, POINTER(IAdviseSink), POINTER(DWORD)]),
("bTonguePosn", BYTE), ("bLipTension", BYTE)] def TextSDATA(text): d = SDATA() d.pData = cast(c_wchar_p(text), c_void_p) d.dwSize = (len(text) + 1) * sizeof(c_wchar) return d class ITTSAttributesW(IUnknown): _iid_ = GUID("{1287A280-4A47-101B-931A-00AA0047BA4F}") ITTSAttributesW._methods_ = [ STDMETHOD(HRESULT, "PitchGet", [POINTER(WORD)]), STDMETHOD(HRESULT, "PitchSet", [WORD]), STDMETHOD(HRESULT, "RealTimeGet", [POINTER(DWORD)]), STDMETHOD(HRESULT, "RealTimeSet", [DWORD]), STDMETHOD(HRESULT, "SpeedGet", [POINTER(DWORD)]), STDMETHOD(HRESULT, "SpeedSet", [DWORD]), STDMETHOD(HRESULT, "VolumeGet", [POINTER(DWORD)]), STDMETHOD(HRESULT, "VolumeSet", [DWORD]) ] ITTSAttributes = ITTSAttributesW class ITTSBufNotifySink(IUnknown): _iid_ = GUID("{E4963D40-C743-11cd-80E5-00AA003E4B50}")