Board index » delphi » DCOM Threading & Object Reference

DCOM Threading & Object Reference

Here is a question for all:

I have a thread that does a CoInitialize(nil), CreateInstance, "Infinite"
Message Loop, and CoUninitialize.

In this message loop I capture messages sent to this thread from other
threads.  What I need to do is to get to the Class Object that this thread
belongs to, in order to get to the callback interface to my client.

Can this object reference only be obtained by doing a QueryInterface to the
Object Factory?

Thanks in advance for your response,
Ed.

 

Re:DCOM Threading & Object Reference


Hello !

I'd like to help you but I fear I did not understand quite well what you
meant to do...

Patrice Corteel

Ed Mazzocca a crit dans le message <6es1qr$3...@forums.borland.com>...

Quote
>Here is a question for all:

>I have a thread that does a CoInitialize(nil), CreateInstance, "Infinite"
>Message Loop, and CoUninitialize.

>In this message loop I capture messages sent to this thread from other
>threads.  What I need to do is to get to the Class Object that this thread
>belongs to, in order to get to the callback interface to my client.

>Can this object reference only be obtained by doing a QueryInterface to the
>Object Factory?

>Thanks in advance for your response,
>Ed.

Re:DCOM Threading & Object Reference


Well perhaps my question was not clear enough.

What I have is a multi-STA DCOM server.  What I require it to do is to get
each thread to communicate with each other.  One way is to use global
variable space.  Another way is to issue PostThreadMessage() in one thread
and capture the events in others.  I prefer the latter.  I got this going
with the code shown below.

Now what I also need to get is the object reference that the thread is
associated with and that is servicing the DCOM interface.  If I can get this
I can issue asynchonous callbacks to each thread's client or use any
method/property associated with my thread (i.e. client).  I got this going
with the use of QueryInterface as shown below.  Is this the only (proper
way) of doing such a thing?  Are there other ideas of how to do this?

Regards,
Ed.

procedure TApartmentThread.Execute;
  CoInitialize(nil);
  FCreateResult := FClassFactory.DoCreateInstance(FUnkOuter, FIID, Unk);
  if FCreateResult = S_OK then
        CoMarshalInterThreadInterfaceInStream(FIID, Unk, IStream(FStream));
  ReleaseSemaphore(FSemaphore, 1, nil);
  if FCreateResult = S_OK then begin
      if Unk.QueryInterface(_clsTheServer, TheServer) = S_OK then begin
             while GetMessage(msg, 0, 0, 0) do
             begin
                    DispatchMessage(msg);
                    Unk._AddRef;
                    if Unk._Release = 2 then
                           break;
                    if msg.message = WM_MYFIRSTMSG then begin
                           TheServer.Get_CallbackInterface.Ping;
                    end;
             end;
      end;
  end;
  TheServer:= nil;
  Unk := nil;
  CoUninitialize;
end;

Other Threads