Any DOM experts?

Miscellaneous Forums/General Discussion/Any DOM experts?

This is killing me, any ideas why this crashes at the get_Script() command? The command does not even return a value - it just dies!

	HRESULT			hr;
	IDispatch*		pDocDisp = NULL;
	IHTMLDocument2* pHTMLDoc = NULL;

	hr = c.cpWebBrowser->get_Document(&pDocDisp);

	if (SUCCEEDED(hr)) 
	{
		hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDoc);
		if (SUCCEEDED(hr)) 
		{
			IDispatch* pScript;

			hr = pHTMLDoc->get_Script(&pScript); // This Crashes the Browser everytime!!!

			ATLASSERT(SUCCEEDED(hr));

			OLECHAR FAR* sMethod = L"igl_DownloadComplete";

		//	CComBSTR bstrMember("igl_DownloadComplete");

			DISPID dispid = NULL;

			hr = pScript->GetIDsOfNames(IID_NULL, &sMethod, 1, LOCALE_SYSTEM_DEFAULT,&dispid);
		
			if (SUCCEEDED(hr)) 
			{	  // invoke assuming no method parameters
				DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
				hr = pScript->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD,&dpNoArgs, NULL, NULL, NULL);
			}
			
			pScript->Release();
			pHTMLDoc->Release();
			return;
		}
	}


I am assuming this a code fragment is running from inside your plug-in. I not 100% sure but experieced a problem with a ChartFx plug in that tried to talk to the script and if site security settings are not just right it crashed the browser. So you might want to look at a security related issue. This problem appeared with security upgrade to IE6. And even thought the plug in was signed we had to mess with Security settings for site to get it worked out.

Strangly our problem does not exists with IE7, so not sure if its the exact issue but might give you somewhere to look.

Doug Stastny

Yeah I mucked with all the security settings, scripting settings etc. it still dies and I'm testing in IE7. It's actually a crash in the mshtml.dll rather than the plugin though.

How are you initializing COM inside your plugin?

CoInitializeEx or CoInitialize?

If CoInitializeEx whats the parameters?

Doug Stastny

I had another thought again based upon just the fragment and the script function your trying to invoke. "igl_DownloadComplete".

Are you downloading in a worker thread? If so is the worker thread atempting to accesses the DOM?

Doug Stastny

Yeah but we don't even get that far :(

The Mozilla version works damn fine, just M$ stoopid implementation of DOM that's doing my head - I can't even debug the stuff!

I think your problem is surrounding the access of the DOM from the worker thread. The DOM is not thread safe.

Your plug-in is activex control "I assume" so that means its apartment thread model to run in IE. Estentially this means its running in the thread context of the DOM. The worker thread is running in different context. When your download is complete post a custom message back to the wndproc of your ActiveX Control eiether via SendMessage if you wish to wait until the message is handled or Postmessage if you wish your thread to continue and handle talking to the script there. That way you are in same context

Hope this helps as been long time since I did activex control plugins for IE.

Doug Stastny

@budman, sounds like a "sound" policy. I know that the page has completed the download as the plugin is run onLoad. I'll try another angle - but thanks for your support and it's nice to know that someone else has had these issues.

No problem.

Good luck

Doug Stastny

Yey it works!!!!!!

It was as simple as calling these functions as soon as the plugin initialised instead of when trying to fire an event.

Thanks Budman!