Re: IOleClientSite->GetContainer fails with E_UNEXPECTED

From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 03/11/05


Date: Fri, 11 Mar 2005 10:19:08 -0500


"Ross" <Ross@discussions.microsoft.com> wrote in message
news:043F1288-3ECF-42E7-B3EC-07A0CDF87EE9@microsoft.com
> I am developing an Active X control that fires off a thread which
> invokes a callback in the control that then calls a Javascript
> function.

See http://www.mvps.org/vcfaq/com/1.htm

> void CTakeFourCtrl::ReturnReading()
> {
> CStringArray params;
> params.Add("Hello!");
> CComPtr<IOleContainer> container; // IOleContainer * container =
> NULL; IOleClientSite * site = this->GetClientSite();

Can't do that. The interface pointer is only valid on original thread,
you have not properly marshalled it to the worker thread.

Why do you want a worker thread in the first place? Note that MSHTML and
script engine are single-threaded components. It's illegal to call them
directly from a worker thread. The best you can do is marshal their
interface pointers to the worker, but then any call from the worker is
marshalled right back to the main thread, executed there, and results
are returned to the worker. So, the worker thread does not actually do
any work.

Unless you have some other long-running task to perform, unrelated to
HTML or script, creating a worker thread is pointless.

-- 
With best wishes,
    Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925 


Relevant Pages

  • Re: Socket is freezing my datagrid
    ... > Do I have to follow any guideline to update my UI control? ... This callback is always executed within a worker thread. ... In order to safely update your datagrid from a worker thread, ... One important thing here is that the Invoke method relies on uiControl to ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Socket is freezing my datagrid
    ... >> Do I have to follow any guideline to update my UI control? ... > This callback is always executed within a worker thread. ... > marshall the call to the method that accesses your datagrid to the UI ... > // This is the method executing ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Multithreading a databound app?
    ... UI control that it is bound to. ... The grid is bound via the BindingSource to WidgetList, ... which is a llist of WidgetItem objects derived from BindingList. ... I had hoped I could populate the list on a worker thread without ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: IOleClientSite->GetContainer fails with E_UNEXPECTED
    ... "Igor Tandetnik" wrote: ... >> invokes a callback in the control that then calls a Javascript ... The interface pointer is only valid on original thread, ... > you have not properly marshalled it to the worker thread. ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Yet another threading/invoking question...
    ... Just tell me - if control is not used at time when its method is called from a worker thread - is it going to lead to an error or not? ... It could be windows framework's code accessing your grid at a time you dont anticipate, ... a$$ considering number of different methods UltraGrid has. ...
    (microsoft.public.dotnet.languages.csharp)