Board index » delphi » Query Interface failing when called from a TThread

Query Interface failing when called from a TThread


2007-10-30 07:36:13 PM
delphi20
I have a COM events interface that uses TConnectionPoint. When an
event occurs the code iterates through the TConnectionPoint.SinkList,
gets a pointer to the IUnknown interface, calls queryinterface for the
event interface then calls the event on the returned event interface.
This works correctly when running in the context of the main thread
but fails and returns nil when running from a TThread.Execute. The
TThread.Execute calls CoInitialize outside a while not Terminated
loop, i.e. when the TThread starts.
Any ideas?
 
 

Re:Query Interface failing when called from a TThread

On 30 Oct, 11:36, "XXXX@XXXXX.COM"
<XXXX@XXXXX.COM>writes:
Quote
I have a COM events interface that uses TConnectionPoint. When an
event occurs the code iterates through the TConnectionPoint.SinkList,
gets a pointer to the IUnknown interface, calls queryinterface for the
event interface then calls the event on the returned event interface.
This works correctly when running in the context of the main thread
but fails and returns nil when running from a TThread.Execute. The
TThread.Execute calls CoInitialize outside a while not Terminated
loop, i.e. when the TThread starts.

Any ideas?
Edit - I mean QueryInterface fails to return the events interface
unless it is called in the context of the main thread.
 

Re:Query Interface failing when called from a TThread

I mean QueryInterface, when executed in the context of a thread other
than the main thread, fails to return the interface I am querying for.
 

Re:Query Interface failing when called from a TThread

I have solved this.
The interfaces cannot be referenced from a thread other than the
thread that created them. COM rules. I use the GIT to get a
reference to the interface.