def doit(): SysStringLen("abc xyz") SysStringLen("abc xyz") SysStringLen(BSTR("abc def"))
def getTextWithFields(self,formatConfig=None): if not formatConfig: formatConfig=config.conf['documentFormatting'] formatConfig['autoLanguageSwitching']=config.conf['speech'].get('autoLanguageSwitching',False) startOffset=self._rangeObj.start endOffset=self._rangeObj.end if startOffset==endOffset: return [] text=BSTR() formatConfigFlags=sum(y for x,y in formatConfigFlagsMap.iteritems() if formatConfig.get(x,False)) res=NVDAHelper.localLib.nvdaInProcUtils_winword_getTextInRange(self.obj.appModule.helperLocalBindingHandle,self.obj.windowHandle,startOffset,endOffset,formatConfigFlags,ctypes.byref(text)) if res or not text: log.debugWarning("winword_getTextInRange failed with %d"%res) return [self.text] commandList=XMLFormatting.XMLTextParser().parse(text.value) for index,item in enumerate(commandList): if isinstance(item,textInfos.FieldCommand): field=item.field if isinstance(field,textInfos.ControlField): item.field=self._normalizeControlField(field) elif isinstance(field,textInfos.FormatField): item.field=self._normalizeFormatField(field) elif index>0 and isinstance(item,basestring) and item.isspace(): #2047: don't expose language for whitespace as its incorrect for east-asian languages lastItem=commandList[index-1] if isinstance(lastItem,textInfos.FieldCommand) and isinstance(lastItem.field,textInfos.FormatField): try: del lastItem.field['language'] except KeyError: pass return commandList
def doit(): func("abcdef") func("abc xyz") func(BSTR("abc def"))
def get_tlib_filename(tlib): # seems if the typelib is not registered, there's no way to # determine the filename. from ctypes import windll, byref from comtypes import BSTR la = tlib.GetLibAttr() name = BSTR() try: windll.oleaut32.QueryPathOfRegTypeLib except AttributeError: # Windows CE doesn't have this function return None if 0 == windll.oleaut32.QueryPathOfRegTypeLib( byref(la.guid), la.wMajorVerNum, la.wMinorVerNum, 0, # lcid byref(name)): full_filename = name.value.split("\0")[0] if not os.path.isabs(full_filename): # workaround Windows 7 bug in QueryPathOfRegTypeLib returning relative path try: dll = windll.LoadLibrary(full_filename) full_filename = _get_module_filename(dll._handle) del dll except OSError: return None return full_filename return None
def test_getname(self): from ctypes import byref, pointer from comtypes import BSTR # This tests a tricky bug, introduced with this patch: # http://www.python.org/sf/1643874 # # Returning a BSTR as an [out] parameter from a server # implementation must transfer the ownership to the caller. # When this is not done, the BSTR instance is SysFreeString'd # too early, and the memory is reused. obj = self.create_object() pb = pointer(BSTR()) # Get the BSTR from the server: obj._ITestComServer__com__get_name(pb) # Retrieve the value, but keep the pointer to the BSTR alive: name = pb[0] # Create sme BSTR's to reuse the memory in case it has been freed: for i in range(10): BSTR("f" * len(name)) # Make sure the pointer is still valid: self.failUnlessEqual(pb[0], name)
def get_tlib_filename(tlib): # seems if the typelib is not registered, there's no way to # determine the filename. from ctypes import windll, byref from comtypes import BSTR la = tlib.GetLibAttr() name = BSTR() try: windll.oleaut32.QueryPathOfRegTypeLib except AttributeError: # Windows CE doesn't have this function return None if 0 == windll.oleaut32.QueryPathOfRegTypeLib(byref(la.guid), la.wMajorVerNum, la.wMinorVerNum, 0, # lcid byref(name) ): return name.value.split("\0")[0] return None
def doit(): BSTR("abcdef" * 100)
def call_GetInstMethod(self): instrMethod = BSTR() p_instrMethod = pointer(instrMethod) silence = self.xrf.GetInstMethod(0, p_instrMethod) return instrMethod.value
def call_GetFilterForScanNum(self, scanNumber): filterEntry = BSTR() p_filterEntry = pointer(filterEntry) silence = self.xrf.GetFilterForScanNum(scanNumber, p_filterEntry) return filterEntry.value