Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.08.14;
Скачать: 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 вся ветка

Текущий архив: 2003.08.14;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.012 c
14-45015
arous
2003-07-29 01:53
2003.08.14
Пассворды и логины юзера


14-45061
Sour
2003-07-27 01:01
2003.08.14
Определение IP адреса машины


14-44967
Ragazor
2003-07-29 11:03
2003.08.14
Появляется ошибка System.pas not found


14-45049
Marser
2003-07-28 10:26
2003.08.14
Именинники 28 июля


14-45013
Леприкон
2003-07-29 07:33
2003.08.14
Цыгане...