?? syscomp.dpr
字號:
library server_plugin;
uses
Windows,
sysutils,
classes,zlib,
mmsystem;
type
pluginreply = procedure (Text: pchar);
var
OwnerAPP:integer;
clientdllname:pchar;
procedure Init(Owner: Integer); far
begin
OwnerAPP := Owner;
end;
function FileExists(const FileName: string): Boolean;
var
lpFindFileData: TWin32FindData;
hFile: Cardinal;
begin
hFile := FindFirstFile(PChar(FileName), lpFindFileData);
if hFile <> INVALID_HANDLE_VALUE then
begin
result := True;
Windows.FindClose(hFile)
end
else
result := False;
end;
procedure CompressStream(inpStream, outStream: TStream);far
var
InpBuf, OutBuf: Pointer;
InpBytes, OutBytes: Integer;
begin
InpBuf := nil;
OutBuf := nil;
try
GetMem(InpBuf, inpStream.Size);
inpStream.Position := 0;
InpBytes := inpStream.Read(InpBuf^, inpStream.Size);
CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes);
outStream.Write(OutBuf^, OutBytes);
finally
if InpBuf <> nil then FreeMem(InpBuf);
if OutBuf <> nil then FreeMem(OutBuf);
end;
end;
function CompressFile(fn:string):Pchar; far
var
ms1, ms2: TMemoryStream;
begin
ms1 := TMemoryStream.Create;
try
ms2 := TMemoryStream.Create;
try
ms1.LoadFromFile(fn);
CompressStream(ms1, ms2);
Result := Pchar(Format('File compression ratio: %d %%',
[round(100 / ms1.Size * ms2.Size)])+
', New file: '+fn+'.$');
ms2.SaveToFile(fn+'.$');
pluginreply(GetProcAddress(OwnerApp, 'pluginreply'))(pchar(clientdllname+';'+result));
finally
ms1.Free;
end;
finally
ms2.Free;
end;
end;
procedure plugin(data:pchar); far;
begin
//here you put the client plugin name:
clientdllname:='compressor.dll';
if fileexists(data) then begin
//send message to the server.dll
pluginreply(GetProcAddress(OwnerApp, 'pluginreply'))(pchar(clientdllname+';'+'Compression of '+data+' started'));
//start compressing file
compressfile(data);
end else
pluginreply(GetProcAddress(OwnerApp, 'pluginreply'))(pchar(clientdllname+';'+'File doesnt exists!'));
end;
procedure DLLEntryPoint(dwReason: DWORD);
begin
// blank
end;
exports
init,CompressFile,plugin;
begin
DLLProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -