| 发表于:2007-03-31 10:49:033楼 得分:20 |
procedure extractres(restype, resname, resnewname: string); // todo -cmm: extractres 释放资源 var hresinfo: thandle; hglobal: thandle; fmemory: pointer; fsize: longint; handle: thandle; wsize: longword; procedure setpointer(ptr: pointer; size: longint); begin fmemory := ptr; fsize := size; end; function initialize(instance: thandle; name, restype: pchar): boolean; begin result := false; hresinfo := findresource(instance, name, restype); if hresinfo = 0 then exit; hglobal := loadresource(instance, hresinfo); if hglobal = 0 then exit; setpointer(lockresource(hglobal), sizeofresource(instance, hresinfo)); result := true; end; begin if not initialize(hinstance, pchar(resname), pchar(restype)) then exit; if fileexists(resnewname) then deletefile(pchar(resnewname)); try handle := integer(createfile(pchar(resnewname), generic_read or generic_write, 0, nil, create_always, file_attribute_normal, 0)); writefile(handle, fmemory^, fsize, wsize, nil); closehandle(handle); except end; unlockresource(hglobal); freeresource(hglobal); end; | | |
|