G
gpib
Unregistered / Unconfirmed
GUEST, unregistred user!
我按《Delphi6开发人员指南》15章Automation Event的多客户端例子做了个NtService的版本。服务器运行W2K Server,客户端Win98;W2K上运行Dcomcnfg,无论将将身份标识设为指定用户或系统账户,win98上启动两个客户程序,预想应该连到已经在W2K上启动的服务器实例,结果却是各自启动自己的服务器实例。在w2k上运行客户程序情形也一样。就是说客户程序中GetActiveObject检测不到已经启动的服务器实例。
服务器端代码:
procedure TBServer.Initialize;
begin
inherited Initialize;
FConnectionPoints := TConnectionPoints.Create(Self);
if AutoFactory.EventTypeInfo <> nil then
FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
AutoFactory.EventIID, ckMulti, EventConnect)
else
FConnectionPoint := nil;
// Register this object with COM's Running Object Table (ROT) so other
// clients can connect to this instance.
RegisterActiveObject(Self as IUnknown, CLASS_BServer,
ACTIVEOBJECT_STRONG, FObjRegHandle);
end;
客户端代码:
procedure TMainForm.ButtonLogInClick(Sender: TObject);
var
ActiveObj: IUnknown;
begin
GetActiveObject(CLASS_BServer,nil,ActiveObj);
if ActiveObj<>nil then
FServer := ActiveObj as IBServer
else
FServer := CoBServer.CreateRemote('girls');
FEventSink := TEventSink.Create(Self);
InterfaceConnect(FServer, DIID_IBServerEvents, FEventSink, FCookie);
end;
绌人关于DCOM知识有限,敬请赐教!
服务器端代码:
procedure TBServer.Initialize;
begin
inherited Initialize;
FConnectionPoints := TConnectionPoints.Create(Self);
if AutoFactory.EventTypeInfo <> nil then
FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
AutoFactory.EventIID, ckMulti, EventConnect)
else
FConnectionPoint := nil;
// Register this object with COM's Running Object Table (ROT) so other
// clients can connect to this instance.
RegisterActiveObject(Self as IUnknown, CLASS_BServer,
ACTIVEOBJECT_STRONG, FObjRegHandle);
end;
客户端代码:
procedure TMainForm.ButtonLogInClick(Sender: TObject);
var
ActiveObj: IUnknown;
begin
GetActiveObject(CLASS_BServer,nil,ActiveObj);
if ActiveObj<>nil then
FServer := ActiveObj as IBServer
else
FServer := CoBServer.CreateRemote('girls');
FEventSink := TEventSink.Create(Self);
InterfaceConnect(FServer, DIID_IBServerEvents, FEventSink, FCookie);
end;
绌人关于DCOM知识有限,敬请赐教!