?
Solved

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

Posted on 2001-07-16
6
Medium Priority
?
730 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

Industry Leaders: 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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