Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-07-16
6
Medium Priority
?
740 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

596 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