把这个程序由DELPHI转换成BCB,在李维《分布系统篇》7-38页,原程序附上!分数好商量! (200分)

  • 主题发起人 主题发起人 Alongsun
  • 开始时间 开始时间
A

Alongsun

Unregistered / Unconfirmed
GUEST, unregistred user!
[brown][/brown][red]Mail: alongsun@sina.com
QQ: 65466700 (24小时在线)
把这个程序由DELPHI转换成BCB,在李维《分布系统篇》7-38页
{*******************************************************}
{ }
{ Midas Socket Server Intercepor Demo }
{ }
{*******************************************************}
unit Intrcptu;
{
NOTE: This demo requires the ZLib units found in the extras directory on the
CD.
The Socket Server has the ability to install an interception COM object that
can be called whenever it receives or sends data. Using this feature, you
can encrypt or compress data using any method you wish. This demo uses the
ZLib compression units that ship on the CD to compress/uncompress all data
going over the wire.
To use this demo;
1) Make sure you have copied the ZLib units from the CD to a directory and
have added that directory to this projects search path.
2) Compile Intrcpt.dpr.
3) Register Intrcpt.DLL using REGSVR32 or TREGSVR on both the client and the
server.
4) On the Server: Bring up the properties for the Socket Server (right click
on the icon in the task bar and select properties) and put the GUID for
Intrcpt.DLL in the Interceptor GUID edit control. The GUID is defined
below as Class_DataCompressor.
5) On the Client: Set the TSocketConnection.InterceptorGUID property to the
Class_DataCompressor GUID and recompile your client.
}
interface
uses
Windows, ActiveX, ComObj, SConnect;
type
{
The interception object needs to implement IDataIntercept defined in
SConnect.pas. This interface has 2 procedures DataIn and DataOut described
below.
}
TDataCompressor = class(TComObject, IDataIntercept)
protected
procedure DataIn(const Data: IDataBlock);
stdcall;
procedure DataOut(const Data: IDataBlock);
stdcall;
end;

const
Class_DataCompressor: TGUID = '{B249776C-E429-11D1-AAA4-00C04FA35CFA}';
implementation
uses ComServ, SysUtils, ZLib, Classes;
{
DataIn is called whenever data is coming into the client or server. Use this
procedure to uncompress or decrypt data.
}
procedure TDataCompressor.DataIn(const Data: IDataBlock);
var
Size: Integer;
InStream, OutStream: TMemoryStream;
ZStream: TDecompressionStream;
p: Pointer;
begin
InStream := TMemoryStream.Create;
try
{ Skip BytesReserved bytes of data }
p := Pointer(Integer(Data.Memory) + Data.BytesReserved);
Size := PInteger(p)^;
p := Pointer(Integer(p) + SizeOf(Size));
InStream.Write(p^, Data.Size - SizeOf(Size));
OutStream := TMemoryStream.Create;
try
InStream.Position := 0;
ZStream := TDecompressionStream.Create(InStream);
try
OutStream.CopyFrom(ZStream, Size);
finally
ZStream.Free;
end;
{ Clear the datablock, then
write the uncompressed data back into the
datablock }
Data.Clear;
Data.Write(OutStream.Memory^, OutStream.Size);
finally
OutStream.Free;
end;
finally
InStream.Free;
end;
end;

{
DataOut is called whenever data is leaving the client or server. Use this
procedure to compress or encrypt data.
}
procedure TDataCompressor.DataOut(const Data: IDataBlock);
var
InStream, OutStream: TMemoryStream;
ZStream: TCompressionStream;
Size: Integer;
begin
InStream := TMemoryStream.Create;
try
{ Skip BytesReserved bytes of data }
InStream.Write(Pointer(Integer(Data.Memory) + Data.BytesReserved)^, Data.Size);
Size := InStream.Size;
OutStream := TMemoryStream.Create;
try
ZStream := TCompressionStream.Create(clFastest, OutStream);
try
ZStream.CopyFrom(InStream, 0);
finally
ZStream.Free;
end;
{ Clear the datablock, then
write the compressed data back into the
datablock }
Data.Clear;
Data.Write(Size, SizeOf(Integer));
Data.Write(OutStream.Memory^, OutStream.Size);
finally
OutStream.Free;
end;
finally
InStream.Free;
end;
end;

initialization
TComObjectFactory.Create(ComServer, TDataCompressor, Class_DataCompressor,
'DataCompressor', 'SampleInterceptor', ciMultiInstance, tmApartment);
end.
[/red]
 
版主呀!
你在做什么,在哪里,为什么我不知道的问题你不回答呀!!!
可以请你的!
 
呀 真不好意思,手头没有CBuilder,我还写不出来
 
呵呵,版主也没有bcb啊,等我装一个试试。
 
晚上熬夜试试,应该比较容易。
 
各位有没有结果呀!
 
大家努力呀,我真的不知道分数给谁!
 
这段好象是定义一个DLL来加密用SOCKET传输入的数据
李维叫作人XX拦截者
我不会C++BUILDER,但是我觉得不难的,
类什么的都一样,照翻就是了
 
我帮你转部份:
#include <windows.h>
#include <activex.hpp>
#include <comobj.hpp>
#include <sconnect.hpp>
#include <comserv.hpp>
#include <sysutils.hpp>
#include <zlib.h>
#include <classes.hpp>
#define Class_DataCompressor "{B249776C-E429-11D1-AAA4-00C04FA35CFA}"
class TDataCompressor: public TComObject,public IDataIntercept
{
protected:
void DataIn(const IDataBlock Data);
void DataOut(const IDataBlock Data);
};
void TDataCompressor::DataIn(const IDataBlock Data)
{
int Size;
TMemoryStream *InStream,*OutStream;
TDecompressionStream *ZStream;
char *p;
InStream = new TMemoryStream;

try{
p = Data.Memory + Data.BytesReserved;
Size = (int)p;
p = p + sizeof(Size);
InStream->Write(p, Data.Size - sizeof(Size));
OutStream =new TMemoryStream;
try{
InStream->Position = 0;
ZStream = new TDecompressionStream(InStream);
try{
OutStream->CopyFrom(ZStream, Size);
}
__finally{
ZStream->Free();
}
Data.Clear();
Data.Write((char *)OutStream->Memory, OutStream->Size);
}
__finally{
OutStream->Free();
}
}
__finally
{
InStream->Free();
}
}
void TDataCompressor::DataOut(const IDataBlock Data)
{
TMemoryStream *InStream, *OutStream;
TCompressionStream *ZStream;
int Size;

InStream =new TMemoryStream;
try{
InStream->Write((char *)(Data.Memory + Data.BytesReserved), Data.Size);
Size = InStream->Size;
OutStream =new TMemoryStream;
try{
ZStream =new TCompressionStream(clFastest, OutStream);
try{
ZStream->CopyFrom(InStream, 0);
}
__finally{
ZStream->Free();
}
Data.Clear();
Data.Write(Size, sizeof(int));
Data.Write((char *)OutStream->Memory, OutStream->Size);
}
__finally{
OutStream->Free();
}
}
__finally{
InStream->Free();
}
}
 
如果你会delphi和bcb的话,就自己改吧!这么简单也要别人做,不会吧!
相信老兄是来送分的吧!看到你后面的问题,好象是说你已解决了,何不结束此问题呢!
 
你可以按書上得做法再BCB里作,然後將自己動手寫得代碼重新用C++寫一下就好了
 
你有没有搞错啊!到处乱帖帖子,你的问题都是这种要耗费别人很多时间的东西
怎么会有人回答呢!!
 
是阿,别以为自己了不起,别人感兴趣才会回答,还那么不谦虚。
 
你还是贴到宝兰交流区吧,偶可不会BCPP ^_*
 
有没有 大侠再帮助我看看是怎么回事了!
 
有心无力呀!!!!!!!!!!!!!!
 
同志们快点帮助小弟呀!
不灵了!
 
Alongsun:
看到你很着急,我很想帮一把,可兄弟目前确实不能回答这个问题,
给你推荐一个网站 http://vcl.vclxx.org
这个网站得到了李维的支持,应该能回答你的问题,
也可以直接给李维本人发E-mail:
gordenl@trd.iii.org.tw <gordenl@trd.iii.org.tw>
不可因问题暂时未解决就对该社区失去信心呀!
 
我猜,
<blue> 你是懂点BCB,不懂delphi吧?</blue>
 
BCB中可以直接使用Delphi的代码,把他加到你的BCB工程用就是了,干嘛还要多此一举!
 
后退
顶部