PRB: You Receive an Unknown Error When You Call a Method of the MFC ActiveX Control (310566)



The information in this article applies to:

  • Microsoft Windows CE 2.11 for the Handheld PC
  • Microsoft Windows CE 2.0 for the Handheld PC
  • Microsoft Windows CE for the Pocket PC

This article was previously published under Q310566

SYMPTOMS

When you attempt to call a method of the MFC ActiveX Control, and the control is hosted in Microsoft Internet Explorer, Pocket Internet Explorer reports an unknown error on the line that calls the method.

CAUSE

This behavior can occur if the IPersistPropertyBag::InitNew method is not called and the control is not initialized properly.

RESOLUTION

To resolve this issue, add a Boolean variable to the control class, and then initialize it to TRUE. Use the MFC ClassWizard to override the OnSetClientSite method. Replace the code inside OnSetClientSite with the following:
if(m_fInitPersist)
{
	IPersistPropertyBag* pPersistPropBag = NULL;
	HRESULT hr = InternalQueryInterface(&IID_IPersistPropertyBag, (void**)&pPersistPropBag);
	if(SUCCEEDED(hr) && pPersistPropBag)
		pPersistPropBag->InitNew();
	m_fInitPersist = FALSE;
}
COleControl::OnSetClientSite();
				

Modification Type:MinorLast Reviewed:7/27/2004
Keywords:kbprb KB310566