我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用win32api.GetLastError()。
def __init__ (self): wx.Frame.__init__ (self, None, title="Clipboard viewer", size=(250,150)) self.first = True self.nextWnd = None # Get native window handle of this wxWidget Frame. self.hwnd = self.GetHandle () # Set the WndProc to our function. self.oldWndProc = win32gui.SetWindowLong (self.hwnd, win32con.GWL_WNDPROC, self.MyWndProc) try: self.nextWnd = win32clipboard.SetClipboardViewer (self.hwnd) except win32api.error: if win32api.GetLastError () == 0: # information that there is no other window in chain pass else: raise
def stop(self): if not self.is_set: self.bus.log('Handler for console events already off.', level=40) return try: result = win32api.SetConsoleCtrlHandler(self.handle, 0) except ValueError: # "ValueError: The object has not been registered" result = 1 if result == 0: self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Removed handler for console events.', level=40) self.is_set = False
def instance_running(self): ''' Use CreateEvent to make sure there is only one instance running ''' if self.SICHECK_EVENT is None: self.SICHECK_EVENT = win32event.CreateEvent( None, 1, 0, self.GUID ) # An instance is already running, quit if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS: win32gui.MessageBox( self.HWND, 'You can only run one instance at a time', 'Seems like KeyCounter is already running', win32con.MB_OK ) return self.stop()
def read_bytes(self, address, bytes = 4): address = int(address) if not self.isProcessOpen: raise ProcessException("Can't read_bytes(%s, bytes=%s), process %s is not open" % (address, bytes, self.pid)) buffer = create_string_buffer(bytes) bytesread = c_ulong(0) data = b'' length = bytes _address = address _length = length while length: if not windll.kernel32.ReadProcessMemory(self.h_process, address, buffer, bytes, byref(bytesread)): if bytesread.value: data += buffer.raw[:bytesread.value] length -= bytesread.value address += bytesread.value if not len(data): raise ProcessException('Error %s in ReadProcessMemory(%08x, %d, read=%d)' % (win32api.GetLastError(), address, length, bytesread.value)) return data data += buffer.raw[:bytesread.value] length -= bytesread.value address += bytesread.value return data
def __init__(self): self.mutexname = "testmutex_{D0E858DF-985E-4907-B7FB-8D732C3FC3B9}" self.mutex = CreateMutex(None, False, self.mutexname) self.lasterror = GetLastError()
def create_mutex(self, argv): try: from win32event import CreateMutex from win32api import GetLastError self.mutexname = "awecode_dr_" + str(argv[0]) self.mutex = CreateMutex(None, False, self.mutexname) self.lasterror = GetLastError() except ImportError: pass
def test_last_error(self): for x in (0, 1, -1, winerror.TRUST_E_PROVIDER_UNKNOWN): win32api.SetLastError(x) self.failUnlessEqual(x, win32api.GetLastError())
def start(self): if self.is_set: self.bus.log('Handler for console events already set.', level=40) return result = win32api.SetConsoleCtrlHandler(self.handle, 1) if result == 0: self.bus.log('Could not SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Set handler for console events.', level=40) self.is_set = True