In the actual development process, encountered such a problem, using the WebBrowser control to open a Web page, the Web page loaded with an OCX control, need to implement two functions, one is to call the Web page JavaScript function, one is the position of the scroll bar in the Mobile Web page. COM component technology is used in all two functions. Also encountered a problem, when the main program is closed, the OCX control in the Web page exception. began to suspect that the OCX control has problems releasing resources, and later debugging found that the WebBrowser control was shut down and the destructor in the OCX control was not executed at all.
The reason was finally found because the idispatch* interface pointer was not freed when two functions were implemented, even if it was passed to another function and released after the function had finished executing.