我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用win32api.LoadLibraryEx()。
def FormatMessage( eventLogRecord, logType="Application" ): """Given a tuple from ReadEventLog, and optionally where the event record came from, load the message, and process message inserts. Note that this function may raise win32api.error. See also the function SafeFormatMessage which will return None if the message can not be processed. """ # From the event log source name, we know the name of the registry # key to look under for the name of the message DLL that contains # the messages we need to extract with FormatMessage. So first get # the event log source name... keyName = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (logType, eventLogRecord.SourceName) # Now open this key and get the EventMessageFile value, which is # the name of the message DLL. handle = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyName) try: dllNames = win32api.RegQueryValueEx(handle, "EventMessageFile")[0].split(";") # Win2k etc appear to allow multiple DLL names data = None for dllName in dllNames: try: # Expand environment variable strings in the message DLL path name, # in case any are there. dllName = win32api.ExpandEnvironmentStrings(dllName) dllHandle = win32api.LoadLibraryEx(dllName, 0, win32con.LOAD_LIBRARY_AS_DATAFILE) try: data = win32api.FormatMessageW(win32con.FORMAT_MESSAGE_FROM_HMODULE, dllHandle, eventLogRecord.EventID, langid, eventLogRecord.StringInserts) finally: win32api.FreeLibrary(dllHandle) except win32api.error: pass # Not in this DLL - try the next if data is not None: break finally: win32api.RegCloseKey(handle) return data or u'' # Don't want "None" ever being returned.
def decode(pathnm): h = win32api.LoadLibraryEx(pathnm, 0, LOAD_LIBRARY_AS_DATAFILE) nm = win32api.EnumResourceNames(h, pefile.RESOURCE_TYPE['RT_VERSION'])[0] data = win32api.LoadResource(h, pefile.RESOURCE_TYPE['RT_VERSION'], nm) vs = VSVersionInfo() j = vs.fromRaw(data) win32api.FreeLibrary(h) return vs
def GetResources(filename, types=None, names=None, languages=None): """ Get resources from dll/exe file. types = a list of resource types to search for (None = all) names = a list of resource names to search for (None = all) languages = a list of resource languages to search for (None = all) Return a dict of the form {type_: {name: {language: data}}} which might also be empty if no matching resources were found. """ hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE) res = _GetResources(hsrc, types, names, languages) win32api.FreeLibrary(hsrc) return res
def FormatMessage( eventLogRecord, logType="Application" ): """Given a tuple from ReadEventLog, and optionally where the event record came from, load the message, and process message inserts. Note that this function may raise win32api.error. See also the function SafeFormatMessage which will return None if the message can not be processed. """ # From the event log source name, we know the name of the registry # key to look under for the name of the message DLL that contains # the messages we need to extract with FormatMessage. So first get # the event log source name... keyName = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (logType, eventLogRecord.SourceName) # Now open this key and get the EventMessageFile value, which is # the name of the message DLL. handle = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyName) try: dllNames = win32api.RegQueryValueEx(handle, "EventMessageFile")[0].split(";") # Win2k etc appear to allow multiple DLL names data = None for dllName in dllNames: try: # Expand environment variable strings in the message DLL path name, # in case any are there. dllName = win32api.ExpandEnvironmentStrings(dllName) dllHandle = win32api.LoadLibraryEx(dllName, 0, win32con.LOAD_LIBRARY_AS_DATAFILE) try: data = win32api.FormatMessageW(win32con.FORMAT_MESSAGE_FROM_HMODULE, dllHandle, eventLogRecord.EventID, langid, eventLogRecord.StringInserts) finally: win32api.FreeLibrary(dllHandle) except win32api.error: pass # Not in this DLL - try the next if data is not None: break finally: win32api.RegCloseKey(handle) return data or '' # Don't want "None" ever being returned.
def __init__(self, atlasPath = None, direction=2): """Intialise the Atlas translation engine Args: atlasPath: a path to atlas; will try and figure it out from registry if not given direction: 1 = JP to ENG, 2 = ENG to JP """ if atlasPath is None: try: atlasPath = findAtlasPath() except MissingAtlasException: print("Could not find ATLAS Translator") atlecont = win32api.LoadLibraryEx(os.path.join(atlasPath, "AtleCont.dll"), 0, LOAD_WITH_ALTERED_SEATCH_PATH) self.createEngine = createEngineType(win32api.GetProcAddress(atlecont, "CreateEngine")) self.destroyEngine = destroyEngineType(win32api.GetProcAddress(atlecont, "DestroyEngine")) self.translatePair = translatePairType(win32api.GetProcAddress(atlecont, "TranslatePair")) self.atlInitEngineData = atlInitEngineDataType(win32api.GetProcAddress(atlecont, "AtlInitEngineData")) self.freeAtlasData = freeAtlasDataType(win32api.GetProcAddress(atlecont, "FreeAtlasData")) intarray1 = intarrayType() intarray2 = intarrayType() genString = b'General' ret = self.atlInitEngineData(c_int(0), c_int(2), byref(intarray1), c_int(0), byref(intarray2)) if ret != 0: raise AtlasInitErrorException() ret2 = self.createEngine(c_int(1), c_int(direction), c_int(0), c_char_p(genString)) if ret2 != 1: raise AtlasInitErrorException()