unit ResUtils;
interface
uses
Windows;
function ReadPEResource(hMod:THandle;ResType
Char;ResName:string;out Data
ointer;out Len:Integer):Boolean;overload;
function ReadPEResource(szFileName:string;ResType
Char;ResName:string;out Data
ointer;out Len:Integer):Boolean;overload;
function WritePEResource(szFileName:string;ResType
Char;ResName:string;Data
ointer;Len:Integer):Boolean;
implementation
function MAKELANGID(PrimaryLang,SubLang:WORD): WORD;
begin
Result:=(SubLang shl 10) or PrimaryLang;
end;
function ReadPEResource(hMod:THandle;ResType
Char;ResName:string;out Data
ointer;out Len:Integer):Boolean;
var
hResInfo,hGlobal:THandle;
pResData
ointer;
begin
Result:=False;
hResInfo:=FindResource(hMod,PChar(ResName),PChar(ResType));
if hResInfo=0 then Exit;
hGlobal:=LoadResource(hMod,hResInfo);
if hGlobal=0 then Exit;
pResData:=LockResource(hGlobal);
Len:=SizeOfResource(hMod,hResInfo);
GetMem(Data,Len);
Move(pResData^,Data^,Len);
UnlockResource(hGlobal);
FreeResource(hGlobal);
Result:=True;
end;
function ReadPEResource(szFileName:string;ResType
Char;ResName:string;out Data
ointer;out Len:Integer):Boolean;
var
hMod:THandle;
begin
hMod:=LoadLibrary(PChar(szFileName));
Result:=(hMod>0) and ReadPEResource(hMod,ResType,ResName,Data,Len);
if hMod>0 then
FreeLibrary(hMod);
end;
function WritePEResource(szFileName:string;ResType
Char;ResName:string;Data
ointer;Len:Integer):Boolean;
var
hUpdate:THandle;
begin
hUpdate:=BeginUpdateResource(PChar(szFileName),False);
Result:=(hUpdate<>0) and UpdateResource(hUpdate,ResType,PChar(ResName),MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),Data,Len);
if hUpdate<>0 then
EndUpdateResource(hUpdate,False);
end;
end.