Autor: DjH | 20.10.2007 |
ExtractResource(FileName:String; Resource:PCHar; DeleteIfExists: Boolean);
Myslím že není co dodat. Další funkce (procedura) je:Run(FileName:string);
Jde o to, že se spustí jakýkoliv soubor v defaultním „prohlížeči toho souboru“. Tedy pokud použiju „Run(‚linkin park.mp3‘)“ otevře se mi tato empétrojka ve WinAmpu nebo Mediaplayeru, prostě v defaultním přehrávači MP3jek :). To je ten rozdíl od API „WinExec“, který umí spouštět jen *.exe, *.com atp… Funkce Run je vlastně tento řádek:
ShellExecute(0,'open',PChar(FileName),nil,nil,0);
Napsal jsem tuto funkci, protože tenhle zápis mě furt nebavil psát dokola :)procedure ExtractResource(FileName:String; Resource:PCHar; DeleteIfExists: Boolean);
//ExtractResource - Function by DjH2oo7
Var
BytesWritten:Integer;
begin
if DeleteIfExists = True then DeleteFile(PChar(FileName));
//Delete the file, if exists
CreateFile(PChar(FileName),
GENERIC_READ + GENERIC_WRITE,
FILE_SHARE_READ + FILE_SHARE_WRITE,
nil,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
0); //Create the file
asm //Now we will work in assembler :)
PUSH EBX //Push the exports of
PUSH EDI
//func. CreateFile
MOV EDI,EAX
//EDI = EAX = fileHandle
end;
FindResource(0,Resource,RT_RCDATA); //Find resource
asm
MOV EBX,EAX //In EAX is Address...
push EAX
push 0
Call LoadResource //Invoke LoadResource,0,eax - Get the address, where resource starts
PUSH EAX
push ebx
push 0
Call SizeofResource //Invoke SizeOfResource,0,ebx,eax - Get the size of res.
POP ECX //Get the handle
lea edx,BytesWritten //BytesWritten - Temp value :)
push 0
push edx
push eax
push ecx
push edi
call WriteFile //Invoke WriteFile,edi,ecx,eax,edx,0
push edi
call CloseHandle
//Close handle of file (EDI)
pop edi
//Zustanou nam ve stacku dve hodnoty,
pop edi
//musime je "vyPOPovat", jinak by RETN neskocil spravne! :)
end;
end;
//###################################################################//
//########################OpenDrive##################################//
procedure OpenDrive;
begin
mciSendString('Set cdaudio door open', nil, 0, hinstance);
end;
//###################################################################//
//########################CloseDrive#################################//
procedure CloseDrive;
begin
mciSendString('Set cdaudio door closed wait', nil, 0, 0);
end;
A v Uses nesmí chybět MMSystem :). A reset a Turn Off://###################################################################//
//#####################ShutDownPC###################################//
Procedure ShutDownPC;
begin
ExitWindowsEx(EWX_Force,0); // potlačí hlášky systému
ExitWindowsEx(EWX_SHUTDOWN,0); // vypnutí počítače
end;
//##################################################################//
//############################RestartPC##############################//
Procedure RestartPC;
begin
ExitWindowsEx(EWX_Force,0); // potlačí hlášky systému
ExitWindowsEx(EWX_REBOOT,0); // restart počítače
end;