How to use the comtypes.automation function in comtypes

To help you get started, we’ve selected a few comtypes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phuslu / pyMSAA / msaa.py View on Github external
def accRole(self):
        '''Get Element Role Name'''
        objChildId = comtypes.automation.VARIANT()
        objChildId.vt = comtypes.automation.VT_I4
        objChildId.value = self.iObjectId
        objRole = comtypes.automation.VARIANT()
        objRole.vt = comtypes.automation.VT_BSTR
        self.IAccessible._IAccessible__com__get_accRole(objChildId, objRole)
        return objRole.value
github enthought / comtypes / comtypes / tools / tlbparser.py View on Github external
if tlib_name is None:
                    tlib_name = "unknown typelib"
                message = "\n\tGetRefTypeInfo failed in %s: %s\n\tgenerating type '%s' instead" % \
                          (tlib_name, details, type_name)
                import warnings
                warnings.warn(message, UserWarning);
                result = typedesc.Structure(type_name,
                                            align=8,
                                            members=[], bases=[],
                                            size=0)
                return result
            result = self.parse_typeinfo(ti)
            assert result is not None, ti.GetDocumentation(-1)[0]
            return result

        elif tdesc.vt == automation.VT_SAFEARRAY:
            # SAFEARRAY(), see Don Box pp.331f
            itemtype = self.make_type(tdesc._.lptdesc[0], tinfo)
            return midlSAFEARRAY(itemtype)

        raise NotImplementedError(tdesc.vt)
github nvaccess / nvda / source / NVDAObjects / IAccessible / winword.py View on Github external
def _get_WinwordDocumentObject(self):
		if not hasattr(self,'_WinwordDocumentObject'): 
			ptr=ctypes.c_void_p()
			if ctypes.windll.oleacc.AccessibleObjectFromWindow(self.windowHandle,IAccessibleHandler.OBJID_NATIVEOM,ctypes.byref(comtypes.automation.IDispatch._iid_),ctypes.byref(ptr))!=0:
				raise OSError("No native object model")
			#We use pywin32 for large IDispatch interfaces since it handles them much better than comtypes
			o=pythoncom._univgw.interface(ptr.value,pythoncom.IID_IDispatch)
			t=o.GetTypeInfo()
			a=t.GetTypeAttr()
			oleRepr=win32com.client.build.DispatchItem(attr=a)
			self._WinwordDocumentObject=win32com.client.CDispatch(o,oleRepr)
 		return self._WinwordDocumentObject
github gccxml / pygccxml / pygccxml / msvc / mspdb / loader.py View on Github external
def as_enum_variant( x ):
    return ctypes.cast( x, ctypes.POINTER( comtypes.automation.IEnumVARIANT ) )
github nvaccess / nvda / source / NVDAObjects / window / excel.py View on Github external
def excelWindowObjectFromWindow(windowHandle):
		try:
			pDispatch=oleacc.AccessibleObjectFromWindow(windowHandle,winUser.OBJID_NATIVEOM,interface=comtypes.automation.IDispatch)
		except (COMError,WindowsError):
			return None
		return comtypes.client.dynamic.Dispatch(pDispatch)
github nvaccess / nvda / source / appModules / powerpnt.py View on Github external
def _getPpObjectModelFromWindow(self,windowHandle):
		"""
		Fetches the Powerpoint object model from a given window.
		"""
		try:
			pDispatch=oleacc.AccessibleObjectFromWindow(windowHandle,winUser.OBJID_NATIVEOM,interface=comtypes.automation.IDispatch)
			return comtypes.client.dynamic.Dispatch(pDispatch)
		except: 
			log.debugWarning("Could not get MS Powerpoint object model",exc_info=True)
			return None
github enthought / comtypes / comtypes / tools / tlbparser.py View on Github external
def make_type(self, tdesc, tinfo):
        try:
            return COMTYPES[tdesc.vt]
        except KeyError:
            pass

        if tdesc.vt == automation.VT_CARRAY:
            typ = self.make_type(tdesc._.lpadesc[0].tdescElem, tinfo)
            for i in range(tdesc._.lpadesc[0].cDims):
                typ = typedesc.ArrayType(typ,
                                         tdesc._.lpadesc[0].rgbounds[i].lLbound,
                                         tdesc._.lpadesc[0].rgbounds[i].cElements-1)
            return typ

        elif tdesc.vt == automation.VT_PTR:
            typ = self.make_type(tdesc._.lptdesc[0], tinfo)
            return PTR(typ)

        elif tdesc.vt == automation.VT_USERDEFINED:
            try:
                ti = tinfo.GetRefTypeInfo(tdesc._.hreftype)
            except COMError, details:
                type_name = "__error_hreftype_%d__" % tdesc._.hreftype
github phuslu / pyMSAA / msaa.py View on Github external
def accRole(self):
        '''Get Element Role Name'''
        objChildId = comtypes.automation.VARIANT()
        objChildId.vt = comtypes.automation.VT_I4
        objChildId.value = self.iObjectId
        objRole = comtypes.automation.VARIANT()
        objRole.vt = comtypes.automation.VT_BSTR
        self.IAccessible._IAccessible__com__get_accRole(objChildId, objRole)
        return objRole.value
github enthought / comtypes / comtypes / server / __init__.py View on Github external
def CreateInstance(self, punkouter=None, interface=None, dynamic=False):
        if dynamic:
            if interface is not None:
                raise ValueError("interface and dynamic are mutually exclusive")
            realInterface = comtypes.automation.IDispatch
        elif interface is None:
            realInterface = comtypes.IUnknown
        else:
            realInterface = interface
        obj = ctypes.POINTER(realInterface)()
        self.__com_CreateInstance(punkouter, realInterface._iid_, ctypes.byref(obj))
        if dynamic:
            return comtypes.client.dynamic.Dispatch(obj)
        elif interface is None:
            # An interface was not specified, so return the best.
            return comtypes.client.GetBestInterface(obj)
        # An interface was specified and obj is already that interface.
        return obj
github nvaccess / nvda / source / NVDAObjects / winword.py View on Github external
def _get_WinwordDocumentObject(self):
		if not hasattr(self,'_WinwordDocumentObject'): 
			ptr=ctypes.POINTER(comtypes.automation.IDispatch)()
			if ctypes.windll.oleacc.AccessibleObjectFromWindow(self.windowHandle,IAccessibleHandler.OBJID_NATIVEOM,ctypes.byref(comtypes.automation.IDispatch._iid_),ctypes.byref(ptr))!=0:
				raise OSError("No native object model")
			self._WinwordDocumentObject=comtypes.client.dynamic.Dispatch(ptr)
 		return self._WinwordDocumentObject