Solved

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

Posted on 2001-07-16
6
688 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
6 Comments
 

Expert Comment

by:tyronen
Comment Utility
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
Comment Utility
I tried this, but it doesn't work. The call to m_spClientSite->GetContainer(&spContainer); doesn't modify spContainer.
0
 

Expert Comment

by:tyronen
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:postrowski
Comment Utility
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
Comment Utility
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
Comment Utility
Points reduced to 0 and placed in PAQ.

Thank you
E-E Moderator
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now