RandomClear icon

Headers for LoadLibrary(Ex)

RandomClear | PRO | 12/09/16 12:51:34 PM UTC | 0 ⭐ | 11045 👁️ | Never ⏰ | []
Delphi |

2.51 KB

|

None

|

0 👍

/

0 👎

unit LibLoaderAPI;
 
interface
 
uses
  Windows;
 
var
  LoadLibraryEx: function(lpFileName: PChar; Reserved: THandle; dwFlags: DWORD): HMODULE; stdcall;
  SetDllDirectory: function(lpPathName: PChar): BOOL; stdcall;
  SetSearchPathMode: function(Flags: DWORD): BOOL; stdcall;
  AddDllDirectory: function(Path: PWideChar): Pointer; stdcall;
  RemoveDllDirectory: function(Cookie: Pointer): BOOL; stdcall;
  SetDefaultDllDirectories: function(DirectoryFlags: DWORD): BOOL; stdcall;
 
function IsKB959426Installed: Boolean;
function IsKB2533623Installed: Boolean;
 
const
  // LoadLibraryEx:
  DONT_RESOLVE_DLL_REFERENCES         = $00000001;
  LOAD_LIBRARY_AS_DATAFILE            = $00000002;
  LOAD_WITH_ALTERED_SEARCH_PATH       = $00000008;
  LOAD_IGNORE_CODE_AUTHZ_LEVEL        = $00000010;
  LOAD_LIBRARY_AS_IMAGE_RESOURCE      = $00000020;
  LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE  = $00000040;
  LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR    = $00000100;
  LOAD_LIBRARY_SEARCH_APPLICATION_DIR = $00000200;
  LOAD_LIBRARY_SEARCH_USER_DIRS       = $00000400;
  LOAD_LIBRARY_SEARCH_SYSTEM32        = $00000800;
  LOAD_LIBRARY_SEARCH_DEFAULT_DIRS    = $00001000;
 
  // SetSearchPathMode:
  BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE  = $00000001;
  BASE_SEARCH_PATH_PERMANENT               = $00008000;
  BASE_SEARCH_PATH_DISABLE_SAFE_SEARCHMODE = $00010000;
 
  // SetDefaultDllDirectories:
  // LOAD_LIBRARY_SEARCH_APPLICATION_DIR = $00000200;
  // LOAD_LIBRARY_SEARCH_USER_DIRS       = $00000400;
  // LOAD_LIBRARY_SEARCH_SYSTEM32        = $00000800;
  // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS    = $00001000;
 
implementation
 
function IsKB959426Installed: Boolean; // XP SP2
begin
  Result := Assigned(SetSearchPathMode);
end;
 
function IsKB2533623Installed: Boolean; // Vista/7 with KB2533623
begin
  Result := Assigned(AddDllDirectory);
end;
 
procedure LoadFuncs;
var
  LibKernel32: HMODULE;
begin
  LibKernel32 := GetModuleHandle(kernel32);
  LoadLibraryEx := GetProcAddress(LibKernel32, {$IFDEF UNICODE}'LoadLibraryExW'{$ELSE}'LoadLibraryExA'{$ENDIF});
  SetDllDirectory := GetProcAddress(LibKernel32, {$IFDEF UNICODE}'SetDllDirectoryW'{$ELSE}'SetDllDirectoryA'{$ENDIF});
  SetSearchPathMode := GetProcAddress(LibKernel32, 'SetSearchPathMode');
  AddDllDirectory := GetProcAddress(LibKernel32, 'AddDllDirectory');
  RemoveDllDirectory := GetProcAddress(LibKernel32, 'RemoveDllDirectory');
  SetDefaultDllDirectories := GetProcAddress(LibKernel32, 'SetDefaultDllDirectories');
end;
 
initialization
  LoadFuncs;
end.

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎