BUG: Error Accessing Window.external in ATL DHTML Control (202009)
The information in this article applies to:
- Microsoft Internet Explorer (Programming) 5
This article was previously published under Q202009 SYMPTOMS
A DHTML control created with the ATL Object Wizard fails with the following script error when accessing window.external from Internet Explorer 5.0:
'Object doesn't support this property or method'
CAUSE
A DHTML control contains two IDispatch interfaces, a default interface for scripting and another for the window.external methods. The WebBrowser control incorrectly uses the default IDispatch interface when invoking window.external methods.
RESOLUTION
Implement the window.external IDispatch method in a separate COM object.
Use the following steps to implement a sub-object for a default ATL DHTML control project:
- Add HTML Control to project (Ctrl).
- Add Simple Object to project, use default of "dual interface" (UIObj).
- Remove original UI dispatch interface (ICtrlUI) from ctrl.h:
From class derivation list:
public IDispatchImpl<ICtrlUI, &IID_ICtrlUI, &LIBID_DHTMLCONTROLLib>,
From COM_MAP, replace the following two lines:
COM_INTERFACE_ENTRY(ICtrlUI)
COM_INTERFACE_ENTRY2(IDispatch, ICtrl)
with
)
COM_INTERFACE_ENTRY(IDispatch)
- Move the example OnClick method from ctrl.h to uiobj.h:
// ICtrlUI
public:
// Example method called by the HTML to change the <BODY> background color
STDMETHOD(OnClick)(IDispatch* pdispBody, VARIANT varColor)
{
CComQIPtr<IHTMLBodyElement> spBody(pdispBody);
if (spBody != NULL)
spBody->put_bgColor(varColor);
return S_OK;
}
- Modify dhtmlcontrol.idl to reflect above changes:
Move OnClick method from ICtrlUI to IUIObj interface definition:
// Example method that will be called by the HTML
HRESULT OnClick([in]IDispatch* pdispBody, [in]VARIANT varColor);
Remove original ICtrlUI interface from interface definition:
[
object, dual,
uuid(C3920EDB-BAD6-11D2-AFA1-00A0C9C9E6C5),
helpstring("ICtrlUI Interface"),
pointer_default(unique)
]
interface ICtrlUI : IDispatch
{
};
Remove original ICtrlUI interface from Ctrl coclass:
interface ICtrlUI;
- Modify OnCreate method in Ctrl.h:
#include "uiobj.h"
...
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CAxWindow wnd(m_hWnd);
HRESULT hr = wnd.CreateControl(IDH_CTRL);
if (SUCCEEDED(hr))
{
// Create sub-object - this implements our window.external methods to be called from HTML
hr = CComObject<CUIObj>::CreateInstance( &m_pUI );
if ( SUCCEEDED(hr) )
{
CComQIPtr<IDispatch> pDisp(m_pUI);
hr = wnd.SetExternalDispatch(pDisp);
}
}
if (SUCCEEDED(hr))
hr = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_spBrowser);
return SUCCEEDED(hr) ? 0 : -1;
}
CComObject<CUIObj>* m_pUI;
- In addition, you can specify that this simple object should not be creatable with CoCreateInstance by marking the object as non-creatable.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. REFERENCESFor more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
For more information about ATL DHTML controls, please refer to the Microsoft Visual C++ 6.0 online documentation.
For additional information, please refer to the following article in the
Microsoft Knowledge Base:
188015 TITLE: HOWTO: Access Methods/Properties of Container from Script
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Mark Davis, Microsoft Corporation.
Modification Type: | Major | Last Reviewed: | 5/11/2006 |
---|
Keywords: | kbBug kbDHTML kbMSHTML kbpending kbWebBrowser KB202009 |
---|
|