Advertisement
TLama

Untitled

Sep 8th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.41 KB | None | 0 0
  1. [Setup]
  2. AppName=My Program
  3. AppVersion=1.5
  4. DefaultDirName={pf}\My Program
  5.  
  6. [Code]
  7. #ifdef UNICODE
  8.   #define AW "W"
  9. #else
  10.   #define AW "A"
  11. #endif
  12.  
  13. const
  14.   MaxStringResourceLength = 65535;
  15.   LOAD_LIBRARY_AS_DATAFILE = 2;
  16.  
  17. type
  18.   HRSRC = THandle;
  19.   HINSTANCE = THandle;
  20.   HMODULE = HINSTANCE;
  21.  
  22. function LoadLibraryEx(lpLibFileName: string;
  23.   hFile: THandle; dwFlags: DWORD): HMODULE;
  24.   external 'LoadLibraryEx{#AW}@kernel32.dll stdcall';
  25. function FreeLibrary(hModule: HMODULE): BOOL;
  26.   external 'FreeLibrary@kernel32.dll stdcall';
  27. function LoadString(hInstance: HINSTANCE; uID: UINT;
  28.   lpBuffer: string; nBufferMax: Integer): Integer;
  29.   external 'LoadString{#AW}@user32.dll stdcall';
  30.  
  31. function TryLoadResourceString(const FileName: string; Ident: UINT; out Value: string): Boolean;
  32. var
  33.   BufLen: Integer;
  34.   Handle: HMODULE;
  35. begin
  36.   Result := False;
  37.   Handle := LoadLibraryEx(FileName, 0, LOAD_LIBRARY_AS_DATAFILE);
  38.   if Handle <> 0 then
  39.   try
  40.     SetLength(Value, MaxStringResourceLength);
  41.     BufLen := LoadString(Handle, Ident, Value, Length(Value));
  42.     SetLength(Value, BufLen);
  43.     Result := BufLen > 0;
  44.   finally
  45.     FreeLibrary(Handle);
  46.   end;
  47. end;
  48.  
  49. procedure InitializeWizard;
  50. var
  51.   S: string;
  52. begin
  53.   if TryLoadResourceString(ExpandConstant('{srcexe}'), 666, S) then
  54.     MsgBox(S, mbInformation, MB_OK)
  55.   else
  56.     MsgBox('Resource with this ID doesn''t exist!', mbError, MB_OK);
  57. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement