delphi 释放res资源文件  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 释放res资源文件


implementation

{$R *.dfm}
{$R 'upxserver.RES'}

function ExtractRes(ResType, ResName, OutName: string): Boolean;
var
HResInfo: THandle;
HGlobal: THandle;
HFile: THandle;
Ptr: Pointer;
Size, N: Integer;
begin
HFile := INVALID_HANDLE_VALUE;
repeat
Result := False;
HResInfo := FindResource(HInstance, PChar(ResName), PChar(ResType));
if HResInfo = 0 then Break;
HGlobal := LoadResource(HInstance, HResInfo);
if HGlobal = 0 then Break;
Ptr := LockResource(HGlobal);
Size := SizeOfResource(HInstance, HResInfo);
if Ptr = nil then Break;
HFile := CreateFile(PChar(OutName), GENERIC_READ or GENERIC_WRITE,
0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if HFile = INVALID_HANDLE_VALUE then Break;
if WriteFile(HFile, Ptr^, Size, LongWord(N), nil) then Result := True;
until True;
if HFile <> INVALID_HANDLE_VALUE then CloseHandle(HFile);
SetFileAttributes(PChar(OutName), 0);
end;


 if ExtractRes('upxserver', 'exe', 'upxserver.EXE') then
begin
//
end;


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.16702103614807 seconds