Вниз
Скачать: CL | DM;

Exe файл внутри ресурса   Найти похожие ветки 

← →
Raki   (2003-06-11 12:54) [0]

Существует проект в который включен ресурс(ехе файл).Как с помощью Win Api сохранить файл из ресурса на диске.


← →
jel ©   (2003-06-11 14:14) [1]

LoadResource вернет
handle to the global memory block containing the data associated with the resource.
Дальше - делай с ним что хочешь.


← →
AlexRush ©   (2003-06-11 15:10) [2]


function ResourceExtractToFile(hInst:DWORD;resName,resType,FullFileName:string):DWORD;stdcall;
var hFile,dw_writed:DWORD;
hRes,hResData:DWORD;
ptrResLock:pointer;
begin
hRes:=FindResourceA(hInstance,PChar(resName),PChar(resType));
if (hRes=0)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("FindResourceA()");{}
{$endif}
result:=1;
exit;
end;
hResData:=LoadResource(hInstance,hRes);
if (hResData=0)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("LoadResource()");
{$endif}
result:=2;
exit;
end;
ptrResLock:=nil;
ptrResLock:=LockResource(hResData);
if not Assigned(ptrResLock)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("LockResource()");
{$endif}
result:=3;
exit;
end;

hFile:= CreateFile(PChar(PathName),
GENERIC_WRITE,
FILE_SHARE_WRITE or FILE_SHARE_READ,
nil,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
if(hFile=INVALID_HANDLE_VALUE)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("CreateFile()");
{$endif}
result:=4;
exit;
end;
dw_writed:=SizeofResource(hInstance,hRes);
if not LongBool(WriteFile(hFile,ptrResLock^,dw_writed,dw_writed,nil))
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("WriteFile()");
{$endif}
CloseHandle(hFile);
result:=5;
exit;
( hFile)

function ResourceExtractToFile(hInst:DWORD;resName,resType,FullFileName:string):DWORD;stdcall;
var hFile,dw_writed:DWORD;
hRes,hResData:DWORD;
ptrResLock:pointer;
begin
hRes:=FindResourceA(hInstance,PChar(resName),PChar(resType));
if (hRes=0)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("FindResourceA()");{}
{$endif}
result:=1;
exit;
end;
hResData:=LoadResource(hInstance,hRes);
if (hResData=0)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("LoadResource()");
{$endif}
result:=2;
exit;
end;
ptrResLock:=nil;
ptrResLock:=LockResource(hResData);
if not Assigned(ptrResLock)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("LockResource()");
{$endif}
result:=3;
exit;
end;

hFile:= CreateFile(PChar(PathName),
GENERIC_WRITE,
FILE_SHARE_WRITE or FILE_SHARE_READ,
nil,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
if(hFile=INVALID_HANDLE_VALUE)
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("CreateFile()");
{$endif}
result:=4;
exit;
end;
dw_writed:=SizeofResource(hInstance,hRes);
if not LongBool(WriteFile(hFile,ptrResLock^,dw_writed,dw_writed,nil))
then begin
{$ifdef DISPLAY_DEBUG_ERRORS}
ErrorMessage("WriteFile()");
{$endif}
CloseHandle(hFile);
result:=5;
exit;
end;
CloseHandle(hFile);
result:=0;
end;


← →
Suntechnic ©   (2003-06-11 15:12) [3]

Дальше - делай с ним что хочешь.

Не совсем так. Дальше с ним LockResource делать надо, а вот уже потом "что хочешь". И, кстати, начинатеся всё не с вызова LoadResource, а с вызова ф-ции FindResource(Ex) результат работы которой уже передаётся в LoadResource.



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.007 c
14-45108
Babenko Alexey
2003-06-05 20:38
2003.08.14
drag and drop


14-45163
Soft
2003-07-30 15:35
2003.08.14
Зачем платить больше


14-45115
Pavel_s
2003-06-11 13:25
2003.08.14
Virtual Desktop


14-45055
Viktor Kushnir
2003-07-28 08:32
2003.08.14
Delphi 6 Service Packs - Где найти?


14-45025
Bartov
2002-12-08 11:58
2003.08.14
Вышел KOL и MCK (v1.58)




   Наверх