Solved

How do I talk to HTML from a worker thread in an ATL ActiveX control?

Posted on 2001-07-16
6
724 Views
Last Modified: 2007-11-27
I want to create an ActiveX control that spawns a worker thread to handle Socket communication stuff. When it recieves socket messages, it should be able to call a Javascript function in HTML. I'm having problems when I call:

   HRESULT hr = m_spClientSite->QueryInterface(IID_IServiceProvider, (void **)&pISP);

The resultant hr is always 0x8000FFFF. As such, I can't drill down to find the IHTMLWindow2 interface, upon which I'd like to call execScript(...).
If I make this function call from the UI thread, everything is OK, but thats not what I need. I understand that I can pass a message from the worker thread to the UI and have the UI thread make the call for me also, but again, thats not what I need.

I've also tried getting the IHTMLWindow2 interface pointer in the UI thread, then calling CoMarshalInterface on that pointer, then calling CoUnmarshalInterface on that object from the worker thread, but that call fails with a value of 0x8003001e. I'm pretty sure this is the right way to go, I think I'm just doing it wrong.

So what I'm looking for are the steps to create a bare-bones ATL project that creates a worker thread, and that worker thread makes a call to execScript on the IHTMLWindow2 interface from m_spClientSite.

If anyone wants, I'm more than happy to email them the bare-bones project files that I've created so far.
0
Comment
Question by:postrowski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:tyronen
ID: 6288235
Try this:

Have your control implement either the IOleObject or the IObjectWithSite interfaces.  You can just inherit these by using the ATL template IOleObjectImpl or IObjectWithSiteImpl.  The first is also available using the ATL Object Wizard in Visual C++.

Then do this:

IOleContainer *spContainer;
m_spClientSite->GetContainer(&spContainer);
IHTMLDocument2 *spDoc;
HRESULT hr = spContainer->QueryInterface(IID_IHTMLDocument2,(void **)&spDoc);
if (FAILED(hr))
return E_NOINTERFACE;
IHTMLwindow2 *spWin;
hr = spDoc->get_parentWindow(&spWin);

Hope this helps

tyronen


0
 

Author Comment

by:postrowski
ID: 6291480
I tried this, but it doesn't work. The call to m_spClientSite->GetContainer(&spContainer); doesn't modify spContainer.
0
 

Expert Comment

by:tyronen
ID: 6291750
In order for the CoUnmarshalInterface function to work, your worker thread must be running in a different apartment.  I don't think client-side controls support multiple apartments.

Have you tried simply passing the interface pointer from one thread to the other?

tyronen
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:postrowski
ID: 6291758
yeah, I've passed the interface pointer, but when I call QueryInterface on it, it always returns 0x8000FFFF.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6828355
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since nobody had an answer for you.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 6845992
Points reduced to 0 and placed in PAQ.

Thank you
E-E Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question