Hi all, I have a problem with an ActiveX I'm developing. I'm trying to call a javascript function from the ActiveX code, which is written in C++ using ATL. I'm doing something like this:

IServiceProvider *serviceProvider = NULL;
IWebBrowser2 *browser = NULL;
IHTMLDocument3 *doc3 = NULL;
IHTMLDocument *doc = NULL;
IHTMLDocument2 *doc2 = NULL;
IDispatch *docDisp = NULL;
IHTMLElement *elem = NULL;
IDispatch* script;
IHTMLWindow2 *win2;
HRESULT hr;

hr = pUnkSite->QueryInterface(IID_IServiceProvider, (void**)&serviceProvider);
if(!SUCCEEDED(hr))
{
return;
}


hr = serviceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&browser);
if(!SUCCEEDED(hr))
{
return;
}

hr = browser->get_Document(&docDisp);
if(!SUCCEEDED(hr))
{
return;
}

hr = docDisp->QueryInterface(IID_IHTMLDocument3, (void**)&doc3);

if(!SUCCEEDED(hr))
{
return;
}

hr = docDisp->QueryInterface(IID_IHTMLDocument, (void**)&doc);

hr = docDisp->QueryInterface(IID_IHTMLDocument2, (void**)&doc2);

if(!SUCCEEDED(hr))
{
return;
}
else
{
hr = doc2->get_parentWindow(&win2);
if(!SUCCEEDED(hr))
{
return;
}

hr = doc1->get_Script(&script);
if(SUCCEEDED(hr))
{
return;
}
}

Both the get_parentWindow and get_Script return an error, e_NOINTERFACE, the other methods all return OK, what am I dong wrong?

thanks