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;

相关阅读 >>

Delphi 自定义产生随机字符串函数

Delphi过滤一段字符里面的html代码的函数

Delphi adoconnection1 事务

Delphi 2009 泛型容器单元(generics.collections)[1]: tlist<t>

Delphi checklistbox用法

Delphi xe7实现的登录窗体的正确用法示例

Delphi的几种类型转换

Delphi button 实现下拉列表

Delphi paramstr 获取外部参数

Delphi 文字的高度与宽度: canvas.textextent

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...