Advertisement
RandomClear

Headers for LoadLibrary(Ex)

Dec 9th, 2016
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.51 KB | None | 0 0
  1. unit LibLoaderAPI;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows;
  7.  
  8. var
  9.   LoadLibraryEx: function(lpFileName: PChar; Reserved: THandle; dwFlags: DWORD): HMODULE; stdcall;
  10.   SetDllDirectory: function(lpPathName: PChar): BOOL; stdcall;
  11.   SetSearchPathMode: function(Flags: DWORD): BOOL; stdcall;
  12.   AddDllDirectory: function(Path: PWideChar): Pointer; stdcall;
  13.   RemoveDllDirectory: function(Cookie: Pointer): BOOL; stdcall;
  14.   SetDefaultDllDirectories: function(DirectoryFlags: DWORD): BOOL; stdcall;
  15.  
  16. function IsKB959426Installed: Boolean;
  17. function IsKB2533623Installed: Boolean;
  18.  
  19. const
  20.   // LoadLibraryEx:
  21.   DONT_RESOLVE_DLL_REFERENCES         = $00000001;
  22.   LOAD_LIBRARY_AS_DATAFILE            = $00000002;
  23.   LOAD_WITH_ALTERED_SEARCH_PATH       = $00000008;
  24.   LOAD_IGNORE_CODE_AUTHZ_LEVEL        = $00000010;
  25.   LOAD_LIBRARY_AS_IMAGE_RESOURCE      = $00000020;
  26.   LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE  = $00000040;
  27.   LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR    = $00000100;
  28.   LOAD_LIBRARY_SEARCH_APPLICATION_DIR = $00000200;
  29.   LOAD_LIBRARY_SEARCH_USER_DIRS       = $00000400;
  30.   LOAD_LIBRARY_SEARCH_SYSTEM32        = $00000800;
  31.   LOAD_LIBRARY_SEARCH_DEFAULT_DIRS    = $00001000;
  32.  
  33.   // SetSearchPathMode:
  34.   BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE  = $00000001;
  35.   BASE_SEARCH_PATH_PERMANENT               = $00008000;
  36.   BASE_SEARCH_PATH_DISABLE_SAFE_SEARCHMODE = $00010000;
  37.  
  38.   // SetDefaultDllDirectories:
  39.   // LOAD_LIBRARY_SEARCH_APPLICATION_DIR = $00000200;
  40.   // LOAD_LIBRARY_SEARCH_USER_DIRS       = $00000400;
  41.   // LOAD_LIBRARY_SEARCH_SYSTEM32        = $00000800;
  42.   // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS    = $00001000;
  43.  
  44. implementation
  45.  
  46. function IsKB959426Installed: Boolean; // XP SP2
  47. begin
  48.   Result := Assigned(SetSearchPathMode);
  49. end;
  50.  
  51. function IsKB2533623Installed: Boolean; // Vista/7 with KB2533623
  52. begin
  53.   Result := Assigned(AddDllDirectory);
  54. end;
  55.  
  56. procedure LoadFuncs;
  57. var
  58.   LibKernel32: HMODULE;
  59. begin
  60.   LibKernel32 := GetModuleHandle(kernel32);
  61.   LoadLibraryEx := GetProcAddress(LibKernel32, {$IFDEF UNICODE}'LoadLibraryExW'{$ELSE}'LoadLibraryExA'{$ENDIF});
  62.   SetDllDirectory := GetProcAddress(LibKernel32, {$IFDEF UNICODE}'SetDllDirectoryW'{$ELSE}'SetDllDirectoryA'{$ENDIF});
  63.   SetSearchPathMode := GetProcAddress(LibKernel32, 'SetSearchPathMode');
  64.   AddDllDirectory := GetProcAddress(LibKernel32, 'AddDllDirectory');
  65.   RemoveDllDirectory := GetProcAddress(LibKernel32, 'RemoveDllDirectory');
  66.   SetDefaultDllDirectories := GetProcAddress(LibKernel32, 'SetDefaultDllDirectories');
  67. end;
  68.  
  69. initialization
  70.   LoadFuncs;
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement