Marshalling a marshalled interface pointer



Can anyone tell me if this is possible?

-----
To provide a bit of background, i am attempting to create an example
application from the O'Reilly book 'Learning DCOM' by Thuan L. Thai. A
complication is that i am using C++Builder and so cannot recreate the
example exactly as it is in the book but i believe the principles are
the same.

I have created a COM dll containing an object 'ChatBrokerObj'. This
object is an ATL object singleton usign the 'free' threaded model. The
component that contains this object holds a container of IUnknown
pointers indexed by string descriptions. The component is hosted in a
COM+ server application and so runs with dllhost.exe.

'ChatBrokerObj' exposes the interface 'IRegisterChatServer' which
provides the method 'HRESULT Register([in] IUnknown * pChatServer,
[in] BSTR bstrDiscussionName );'

It also exposes the interface 'IDiscussions' which provides the method
'HRESULT GetChatServer([in] BSTR bstrDiscussion, [out] IUnknown **
ppUnk );'

I have also created a simple GUI application named 'ChatServer.exe'
which contains an ATL object 'ChatServerObj'. This object is also
'free' threaded. ChatServerObj exposes the interface 'ISendMessage'
which provides the method 'HRESULT Talk([in] BSTR bstrMessage );'

When 'ChatServer' is run the IRegisterChatServer interface is
retrieved for the 'ChatBrokerObj' using the CoCreateInstanceEx
mechanism (first obtaining the IUnknown which is then queried for
IRegisterChatServer). ChatServer.exe then instantiates ChatServerObj
retrieving its IUnknown which it registers with the ChatBroker via
IRegisterChatServer->Register(_bstr_t("Server1"), m_pIUnknown);

Another 'ChatServer' is started and registers itself with the
ChatBroker with the name "Server2".

Now, "Server1" calls IDiscussions->GetChatServer("Server2", &pUnkSvr2)
to retrieve "Server2"'s IUnknown interface pointer which succeeds.

In the ChatBrokers implementation of GetChatServer, for debug
purposes, i query the contained IUnknown pointer for "Server2" for its
'ISendMessage' interface which succeeds and i can then successfully
call ISendMessage->Talk("Called from broker"), i release this
interface before returning the contained IUnknown to the ChatServer
("Server1") application.

"Server1" now calls QueryInterface for 'ISendMessage' on the returned
"Server2"'s IUnknown. This succeeds. If i then call ISendMessage-
Talk("Called from Server1"); i get an hr of 0xC0000005 which
translates to an access violation.

If i use "Server1" to query for "Server1" (i.e. its own IUnknown) from
the ChatBroker the ISendMessage call works.

As far as i can tell it looks like the registration of an IUnknown
with the ChatBroker successfully marshalls the ChatServer interface
into the ChatBroker process and any thread acessing ChatBroker can
sucessfully use any registered IUnknown interface. I am assuming that
the registered IUnknowns are actually proxies to the respective
ChatServer.exe contained objects.

When i then attempt to retrieve a registered IUnknown to another
process its as if the method 'GetChatServer([in] BSTR bstrDiscussion,
[out] IUnknown ** ppUnk );' is incorrectly marshalling the ChatBroker
held 'marhsalled' interface, slightly confused as to why
QueryInterface would return sucessfully with a bad ISendMessage
pointer.
--------

To summarise, i beleive i am attempting to marshall an interface into
another process that is itself a marshalled interface pointer from
another process. All interfaces are defined as 'oleautomation' so type
library marshalling is being employed (i have confirmed this in the
registry entries for the interfaces).

Q1. I am assuming type library marshalling can handle an [out]
IUnknown (i.e. IUnknown**).

Q2. I appreciate that this may be a C++Builder issue but in principle
should this work? or am i missunderstanding the location transparency
concept of DCOM?

Q3. Could COM+ be an issue here?

Happy to post code extracts just wanted to confirm if what i am
attempting should be possible.

Regards
Gary

.



Relevant Pages

  • Re: IUnknown interface
    ... both directly derived from IUnknown. ... two different implementations (note that usually both interface tables ... ULONG STDMETHODCALLTYPE Release ... virtual HRESULT DoSomething ...
    (microsoft.public.vc.language)
  • Re: Dual interface
    ... and exposes IDispatch (it must expose IUnknown ... I think the law should be every interface of the COM component implements, ... If a component implements a customized interface, ... then we could invoke the ...
    (microsoft.public.vc.language)
  • Re: ATL and object aggregation (more)
    ... I don't think you should call Releaseon an interface's pointer. ... an helper method that is called by the 'true' COM interface method ... > It's wrong because the IUnknown interface will be lost during the Query ... then the IInObj3Ptr InObj3Ptr constructor is ...
    (microsoft.public.vc.atl)
  • Re: Simple IUnknown Example
    ... IUnknown is the base interface for all COM interfaces. ... If you are interested in ATL, I will also recommend you to ...
    (microsoft.public.win32.programmer.ole)

Loading