关于一些资料!不求解只求答! ( 积分: 100 )

  • 主题发起人 主题发起人 6713828
  • 开始时间 开始时间
6

6713828

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在已经写好了一套软件,但是下载时遇到了麻烦!
我看过讯雷好像有他专用的协议!
大家看看讯雷的连接地址!
thunder://QUFodHRwOi8vZGF0Ni5zb3NvZmxhc2guY29tL2RhdGEvdHQoYmJzLnV1YmlyZC5jb20pLnJtdmJaWg==
好像是注册到控件;Thunder/ComDlls/ThunderAgent_007.dll和Thunder/ComDlls/XunLeiBHO_007.dll
还有:
像telnet:192.168.1.1
还有:
mailto:www@www.com
等......
但是我想自己写一个自己的协议.不知道冲和下手!
希望大家给我指点一下!
有源码最好,如果分不够在加!
 
unit trmnsh;
interface
uses Windows, ActiveX, UrlMon, ComObj, ComServ;
const
CLASS_TRMNSH: TGUID = '{4C8B0C85-6E14-4B46-AC6B-E4D8678E60B3}';
type
TtrmNSHObj = class(TComObject, IInternetProtocol)
private
Furl: string;
Fstream: IStream;
Fsink: IInternetProtocolSink;
Ftotal: integer;
public
function Start(szUrl: LPCWSTR; OIProtSink: IInternetProtocolSink;
OIBindInfo: IInternetBindInfo; grfPI, dwReserved: DWORD): HResult;stdcall;
function Continue(const ProtocolData: TProtocolData): HResult; stdcall;
function Abort(hrReason: HResult; dwOptions: DWORD): HResult; stdcall;
function Terminate(dwOptions: DWORD): HResult; stdcall;
function Suspend: HResult; stdcall;
function Resume: HResult; stdcall;

function Read(pv: Pointer; cb: ULONG; out cbRead: ULONG): HResult; stdcall;
function Seek(dlibMove: LARGE_INTEGER; dwOrigin: DWORD; out libNewPosition: ULARGE_INTEGER): HResult; stdcall;
function LockRequest(dwOptions: DWORD): HResult; stdcall;
function UnlockRequest: HResult; stdcall;
end;

TOnAcceptEvt = procedure(Sender: TObject;const sUrl: string;var bAccept: boolean) of object;
TOnGetContentEvt = procedure(Sender: TObject;const sUrl: string;const content: IStream) of object;

TtrmhProtocolObj = class
private
FFactory: IClassFactory;
FInternetSession: IInternetSession;
FProtocolName: string;
FEnabled: boolean;
FOnAccept: TOnAcceptEvt;
FOnGetContent: TOnGetContentEvt;
procedure setEnabled(const Value: boolean);
procedure setProtocolName(const Value: string);
protected
function accept(const sUrl: string): boolean;
procedure getContent(const sUrl: string;const content: IStream);
public
constructor Create(const cof: TComObjectFactory);
destructor Destroy;override;
published
property ProtocolName: string read FProtocolName write setProtocolName;
property Enabled: boolean read FEnabled write setEnabled;
property OnAccept: TOnAcceptEvt read FOnAccept write FOnAccept;
property OnGetContent: TOnGetContentEvt read FOnGetContent write FOnGetContent;
end;

var
gtrmh: TtrmhProtocolObj = nil;
implementation
{ TtrmNSHObj }

function TtrmNSHObj.Abort(hrReason: HResult; dwOptions: DWORD): HResult;
begin
result:= E_NOTIMPL;
end;

function TtrmNSHObj.Continue(const ProtocolData: TProtocolData): HResult;
begin
result:= E_NOTIMPL;
end;

function TtrmNSHObj.LockRequest(dwOptions: DWORD): HResult;
begin
result:= S_OK;
end;

function TtrmNSHObj.Read(pv: Pointer; cb: ULONG;out cbRead: ULONG): HResult;
begin
result:= S_FALSE;
if (Fstream <> nil) and Succeeded(Fstream.Read(pv, cb, @cbRead)) and (cbRead > 0) then
result:= S_OK;
end;

function TtrmNSHObj.Resume: HResult;
begin
result:= E_NOTIMPL;
end;

function TtrmNSHObj.Seek(dlibMove: LARGE_INTEGER; dwOrigin: DWORD;
out libNewPosition: ULARGE_INTEGER): HResult;
begin
result:= E_NOTIMPL;
end;

function TtrmNSHObj.Start(szUrl: LPCWSTR;
OIProtSink: IInternetProtocolSink; OIBindInfo: IInternetBindInfo; grfPI,
dwReserved: DWORD): HResult;
var
i64: int64;
begin
result:= S_FALSE;
Furl:= WideCharToString(szUrl);
Fsink:= OIProtSink;
if gtrmh.accept(Furl) then begin
Fstream:= nil;
CreateStreamOnHGlobal(0, True, FStream);
gtrmh.getContent(Furl, Fstream);
Fstream.Seek(0, STREAM_SEEK_END, i64);
Ftotal:= i64;
Fstream.Seek(0, STREAM_SEEK_SET, i64);
Fsink.ReportData(BSCF_FIRSTDATANOTIFICATION or
BSCF_LASTDATANOTIFICATION or BSCF_DATAFULLYAVAILABLE, 0, Ftotal);
Fsink.ReportResult(S_OK, S_OK, nil);
result:= S_OK;
end else result:= S_FALSE;
end;

function TtrmNSHObj.Suspend: HResult;
begin
result:= E_NOTIMPL;
end;

function TtrmNSHObj.Terminate(dwOptions: DWORD): HResult;
begin
Fstream:= nil;
Fsink:= nil;
result:= S_OK;
end;

function TtrmNSHObj.UnlockRequest: HResult;
begin
result:= S_OK;
end;

{ TtrmhProtocol }

constructor TtrmhProtocolObj.Create(const cof: TComObjectFactory);
begin
inherited Create;
FProtocolName:= 'trmh';
FFactory:= cof;
end;

destructor TtrmhProtocolObj.Destroy;
begin
setEnabled(False);
FFactory:= nil;
FInternetSession:= nil;
inherited;
end;

procedure TtrmhProtocolObj.setEnabled(const Value: boolean);
begin
if FEnabled <> value then begin
FEnabled := Value;
if FEnabled then begin
if FFactory = nil then
CoGetClassObject(CLASS_TRMNSH, CLSCTX_SERVER, nil, IClassFactory, FFactory);
if FInternetSession = nil then
CoInternetGetSession(0, FInternetSession, 0);
FInternetSession.RegisterNameSpace(FFactory, CLASS_TRMNSH, PWideChar(WideString(FProtocolName)), 0, nil, 0);
end else begin
if (FFactory <> nil) and (FInternetSession <> nil) then
FInternetSession.UnregisterNameSpace(FFactory, PWideChar(WideString(FProtocolName)));
end;
end;
end;

procedure TtrmhProtocolObj.setProtocolName(const Value: string);
begin
if FProtocolName <> value then begin
if FEnabled then begin
setEnabled(False);
FProtocolName:= Value;
setEnabled(True);
end else FProtocolName:= Value;
end;
end;

function TtrmhProtocolObj.accept(const sUrl: string): boolean;
begin
result:= False;
if Assigned(FOnAccept) then FOnAccept(Self, sUrl, result);
end;

procedure TtrmhProtocolObj.getContent(const sUrl: string;
const content: IStream);
begin
if Assigned(FOnGetContent) then FOnGetContent(Self, sUrl, content);
end;

initialization
gtrmh:= TtrmhProtocolObj.Create(TComObjectFactory.Create(ComServer, TtrmNSHObj, CLASS_TRMNSH, 'TRMNSH', 'TrustMe Name Space Handler', ciMultiInstance));
finalization
gtrmh.Free;
end.
 
老大,你把源码发给我吧,我的油箱是6713827@qq.com!
这样不太容易看懂!
谢谢了。
有源码马上结贴!
 
老大,你把源码发给我吧,我的邮箱是6713827@qq.com!
这样看了代码,也不知道从何下手!
哎!
希望有源码!
 
老大不见了
 
老大,还能有什么源码!?
这就全了,你自己实现onAccept和onGetContent就可以了。
我给的是电子书中常用的代码。
你把代码拷贝下来不就能用了么!?
如果要实现进程外像CHM那种,还要在注册表的HKEY_CLASSES_ROOT/PROTOCOLS/Handler下注册你的协议
 
不是,明白点,但是我新建工程都不太清楚属于那一类工程啊,是不是ACTIVEX工程?
老大?
 
1、进程内使用,像ebook那种:建一个普通的program,在初始化时将trmh.Enabled:= True;
2、进程外使用,像chm那种,在注册表HKEY_CLASSES_ROOT/PROTOCOLS/Handler下注册mk键值:(mk是chm使用的协议)
建一个普通的dll,导出DllGetClassObject,DllRegisterServer,DllUnregisterServer,DllCanUnloadNow四个函数,注册此dll即可。
qq:22627167
 
老大的QQ有问题设置啊.不知道你的名字!哎,能发我一份例子吗?
我的EMAIL:6713827@QQ.COM
说了这么多,还是不太明白,看代码我感觉最容易懂了。
 
老大也不说话,希望有人发我一份例子,哎,我在去别的地方看看。
 
老大来看看啊。
我建立的一个普通程序,代码:
library Project1;

uses
SysUtils,
Classes,
ComServ,
trmnsh in 'trmnsh.pas';

{$R *.res}

exports
DllGetClassObject,
DllRegisterServer,
DllUnregisterServer,
DllCanUnloadNow;
begin
gtrmh.Enabled:=True;
end.
注册后,但是未发现你所说的HKEY_CLASSES_ROOT/PROTOCOLS/Handler下面的协议!
急救!!!
 
终于看明白了,谢谢老大,但是还有一个问题想问问,
我准备是进程外使用。注册后,
function TtrmhProtocolObj.accept(const sUrl: string): boolean;
begin
result:= False;
if Assigned(FOnAccept) then FOnAccept(Self, sUrl, result);
end;

procedure TtrmhProtocolObj.getContent(const sUrl: string;
const content: IStream);
begin
if Assigned(FOnGetContent) then FOnGetContent(Self, sUrl, content);
end;
这两个代码怎么才能获取参数啊?
是不是:sUrl:就是获取到的参数呢?
老大!
 
好了老大,你太棒了!
不知道该怎么感谢你!
我太爱你了。
要么我嫁给你吧!
 
已经全部读懂了!
 
还有,老大,能不能把你的进程内使用说明白一点啊?
我的不知道怎么用不到。
program P2P_CLIENT;

uses
Forms,
UnitMainForm in 'UnitMainForm.pas' {MainForm},
Protocol in '../P2P_COMMON/Protocol.pas',
CRC32 in 'CRC32.pas',
simplesocks in '../P2P_COMMON/simplesocks.pas',
Functions in '../P2P_COMMON/Functions.pas',
New in 'New.pas' {Form1},
P2Putils in '../P2P_COMMON/P2Putils.pas',
trmnsh in '../P2P_COMMON/trmnsh.pas';

{$R *.res}

begin
gtrmh.Enabled:=True;
Application.Initialize;
Application.Title := 'P2PC;
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
在创建窗体事加上gtrmh.Enabled:=True;这句也不行!
不知道那里出问题了,老大!
 
还有,老大,能不能把你的进程内使用说明白一点啊?
我的不知道怎么用不到。
program P2P_CLIENT;

uses
Forms,
UnitMainForm in 'UnitMainForm.pas' {MainForm},
Protocol in '../P2P_COMMON/Protocol.pas',
CRC32 in 'CRC32.pas',
simplesocks in '../P2P_COMMON/simplesocks.pas',
Functions in '../P2P_COMMON/Functions.pas',
New in 'New.pas' {Form1},
P2Putils in '../P2P_COMMON/P2Putils.pas',
trmnsh in '../P2P_COMMON/trmnsh.pas';

{$R *.res}

begin
gtrmh.Enabled:=True;
Application.Initialize;
Application.Title := 'P2PC;
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
在创建窗体事加上gtrmh.Enabled:=True;这句也不行!
不知道那里出问题了,老大!
 
提供一段代码给你:
unit main;
interface
uses Windows, Messages, ActiveX, SysUtils, CommDlg, myshdocvw;

function dlgproc(const hDlg, uMsg, wParam, lParam: Cardinal): BOOL;stdcall;

implementation
uses trmhSvr, async, trmnsh, commvar;

procedure trm1About;
resourcestring
resAbout = ' ╭⌒╮┅~ ¤ ╭⌒╮ '#10#13+
' ╭⌒╭⌒╮╭⌒╮~╭⌒╮ ︶ ,︶︶ '#10#13+
' ,︶︶︶︶,''︶~~ ,''~︶︶ ,'' '#10#13+
' ╔ ╱◥███◣═╬╬╬╬╬╬╬╬╬╬╗'#10#13+
' ╬ ︱田︱田 田 ︱ ╬'#10#13+
' ╬ Author: TrustMe ╬'#10#13+
' ╬ ╭○╮● Email: yu3350@sina.com ╬'#10#13+
' ╬ /■//■/ QQ: 22627167 ╬'#10#13+
' ╬ <| || TrustMe制作,必属精品! ╬'#10#13+
' ╬ ╬'#10#13+
' ╚╬╬╬╬╬╬╬╬╬╬╗ ╔╬╬╬╬╬╝'#0;

begin
MessageBox(GetActiveWindow, PChar(resAbout), '关于...', MB_OK or MB_ICONINFORMATION);
end;

function createComObj(const clsid: TGuid): IUnknown;
var
cf: IClassFactory;
begin
CoGetClassObject(clsid, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, nil, IClassFactory, cf);
if cf <> nil then try
cf.CreateInstance(nil, iUnknown, result);
finally
cf:= nil;
end;
end;

type
TempObj = object
procedure onProtocolAccept(Sender: TObject;const URL: String; var Accept: Boolean);
procedure onProtocolContent(Sender: TObject;const URL: String;const Stream: IStream);
end;

procedure TempObj.onProtocolAccept(Sender: TObject;const URL: String; var Accept: Boolean);
begin
Accept:= Pos(gtrmh.ProtocolName, LowerCase(url)) = 1;
end;

procedure TempObj.onProtocolContent(Sender: TObject;const URL: String;const Stream: IStream);
var
svr: TSimpleHttpSvrObj;
s: string;
begin
svr:= queueSimpleHttpSvr(Stream);
try
s:= 'GET ' + Copy(url, Length(gtrmh.ProtocolName) + 2, Length(url));
svr.processRequest(@s[1], Length(s));
finally
freeSimpleHttpSvr(svr);
end;
end;

var
web: IWebBrowser2;
t: Tempobj;

procedure goHome(const hdlg: Cardinal);
var
url: OleVariant;
ev: OleVariant;
begin
url:= gtrmh.ProtocolName + ':/';
web.Navigate2(url, ev, ev, ev, ev);
// 标题
SetWindowText(hdlg, @gTitle[1]);
end;

procedure openTrm(const hdlg: Cardinal);
var
fn: tagOFNA;
bu: array[0..9999]of Char;
begin
ZeroMemory(@fn, SizeOf(fn));
ZeroMemory(@bu[0], SizeOf(bu));
fn.lStructSize:= SizeOf(fn);
fn.hWndOwner:= hdlg;
fn.hInstance:= hInstance;
fn.lpstrFilter:= 'TRM文件'#0'*.trm;*.trm1;*.archive'#0'可执行文件(EXE)'#0'*.exe'#0#0;
fn.lpstrFile:= @bu[0];
fn.nMaxFile:= SizeOf(bu);
if GetOpenFileName(fn) and openTrmFile(@bu[0]) then
goHome(hdlg);
end;

procedure saveAs(const hdlg: Cardinal);
begin
if saveTrmFile(gtrm, nil) then
MessageBox(hdlg, '保存成功!', '提示', MB_OK or MB_ICONINFORMATION);
end;

function dlgproc(const hDlg, uMsg, wParam, lParam: Cardinal): BOOL;

var
ii: IUnknown;
hm: HMENU;
begin
case uMsg of
WM_CLOSE:PostQuitMessage(0);
WM_INITDIALOG:begin
CoInitialize(nil);
// 菜单
hm:= LoadMenu(hInstance, 'MAINMENU');
SetMenu(hdlg, hm);
SendMessage(hdlg, WM_SETICON, ICON_SMALL, LoadIcon(hInstance, 'MAINICON'));

web:= createComObj(CLASS_WebBrowser) as IWebBrowser2;
AtlAxAttachControl(web, hDlg, ii);

gContentTypeLock:= criticalSectionNew;
gQueueLock:= criticalSectionNew;

gtrmh.OnAccept:= t.onProtocolAccept;
gtrmh.OnGetContent:= t.onProtocolContent;
gtrmh.ProtocolName:= 'trmh';
gtrmh.Enabled:= True;
goHome(hdlg);
end;
WM_DESTROY:begin
gContentTypeLock.Free;
gContentTypeLock:= nil;
gQueueLock.Free;
gQueueLock:= nil;
end;
WM_COMMAND:case wParam of
// 文件
101:openTrm(hdlg);
102:saveAs(hdlg);
103:SendMessage(hdlg, WM_CLOSE, 0, 0);
// 导航
201:try web.GoBack;except end;
202:try web.GoForward;except end;
203:web.Stop;
204:web.Refresh;
205:goHome(hdlg);
// 帮助
301:trm1About;
end;
end;
result:= False;
end;

end.


http://free5.ys168.com/?trustme
 
这段代码必须用到TWebBrowser控件吧?
明白你的意思,我在想想其他方法,老大真是战无不胜啊!
 
后退
顶部