An error is reported when the ActiveX control is embedded into a webpage and the webpage is closed.

Source: Internet
Author: User

Http://community.csdn.net/Expert/topic/3160/3160265.xml? Temp =. 5274317.

The problem you are talking about is generally a pointer problem. It is likely that the resources are not securely released.

You can check whether finalrelease exists. If not, you need to go to the ioleobject_close Release Interface (the interface cannot be released due to cross-reference) to ensure resource security.

Corresponds

Ioleobject_setclientsite
Ioleobject_close

When overwriting these two methods, you must call the corresponding ccomcontrolbase method.
Bytes -------------------------------------------------------------------------------------------

(Conversion) Problem: in IE, The wm_create and wm_destory processing functions of ActiveX controls are not called.

Overview

IE does not create ActiveX control until the control is visible for the first time and calls the wm_create processing code. The wm_destory processing code is not called when the page is left or closed. The same problem occurs when the control size is 0*0. If you access the control window or subwindow before (for example, in the Code for processing the window. onload event), it will not succeed.

Cause

Most ActiveX control frameworks, such as MFC and ATL, create controls when activating ActiveX controls locally. Based on performance considerations, ie only activates ActiveX controls locally until the control is visible for the first time. In this way, web pages containing ActiveX controls are loaded more quickly and occupy less memory. This also makes the wm_create code of the ActiveX control not called until the control is visible for the first time.

If the control supports non-window activation, ie will create the control in non-window activation mode, so that the wm_destory processing code of the control will not be called when the page is left or closed.

Solution

When you initialize or exit the page, ie calls the ioleobject: setclientsite Implementation of the ActiveX control on the page, regardless of whether the control is locally activated. During page initialization, the passed pointer is the host's ioleclientsite interface pointer. When the page is left or closed, the passed pointer is a null pointer. You can use this pointer to determine the control status and execute the initialization or clearing code.

MFC

The implementation of MFC for ioleobject: setclientsite () includes the call to the virtual function colecontrol: onsetclientsite. In this case, you can determine whether the control is loaded or cleared based on whether m_pclientsite is a null pointer.

// Cmycontrol is derived from colecontrol.
Void cmycontrol: onsetclientsite ()
{
If (m_pclientsite)
// The parent window and its size are not important, because the control is automatically re-painted and relocated when it is activated locally.
Verify (createcontrolwindow (: getshorttopwindow (), crect (,), crect )));
Else
Destroywindow ();
Colecontrol: onsetclientsite ();
}

ATL

The implementation of ATL for ioleobject: setclientsite () has an ioleclientsite parameter (MFC saves this pointer to colecontrol: m_pclientsite in the implementation of ioleobject: setclientsite ), you just need to judge it. At the same time, ATL does not reset the control's parent window, so the control needs to be manually activated locally.

// Cmycontrol is derived from ccomcontrol
Stdmethod (setclientsite) (ioleclientsite * pclientsite)
{
If (pclientsite)
{
Rect rc = {0, 0, 0 };
// Don't have access to the container's window so just use
// Desktop. window will be resized correctly during in-place
// Activation.
Hwnd = createcontrolwindow (: getshorttopwindow (), RC );
_ Assert (hwnd );
}
Else
: Destroywindow (m_hwnd );
Return ioleobjectimpl: setclientsite (pclientsite );
}

Hresult inplaceactivate (long iverb, const rect * prcposrect)
{
// Get the container's window. _ assert (m_spclientsite );
Lpoleinplacesite pinplacesite = NULL;
Hresult hR = m_spclientsite-> QueryInterface (iid_ioleinplacesite, (void **) & pinplacesite );
_ Assert (succeeded (HR) & pinplacesite );
Hwnd hparent = NULL;
HR = pinplacesite-> getwindow (& hparent );
_ Assert (succeeded (HR) & hparent );
Pinplacesite-> release ();
// Set container window as our parent window
Setparent (hparent); <br> return ccomcontrolbase: inplaceactivate (iverb, prcposrect); <br>}

Steps to reproduce the problem

Use MFC or ATL to create an ActiveX Control
Add the processing functions of the two messages
Use ie as the debugging program
Reference

ActiveX Control containers (Internet Development SDK)
KB q195188 PRB: ActiveX control window is not created until visible in Internet Explorer
Notes on implementing an ole control container (kraig brockschmidt)
Introduction to ActiveX Controls (Internet Development SDK)
Reusing mshtml (Internet Development SDK)
Use ATL and MFC to create ActiveX Controls (George Shepherd)

--------------------------------------
Resource http://support.microsoft.com/default.aspx? SCID = KB; en-US; 195188

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.