Главная страница
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.01 c
14-45155
3asys
2003-07-30 17:04
2003.08.14
Работа с электронной подписью в Delphi


14-44974
Andriy
2003-07-30 10:38
2003.08.14
SpinEdit в D7 ???


14-45031
АТ
2003-07-28 14:50
2003.08.14
Из Делфи 7 исчезли компоненты. Чем их заменить?


14-44976
Mystex
2003-07-28 13:17
2003.08.14
Помогите выбрать книгу по Delphi


14-45039
Best Gun
2003-07-19 15:19
2003.08.14
Хочу задать несколько вопросов