The following Visual C++ source code demonstrates how to implement this in your own application. This code uses smart pointers created by the #import statement. You must include this #import statement in one of your source code files, preferably Stdafx.h:
#import "C:\winnt\system32\mshtml.tlb " // location of mshtml.tlb
void CMyClass::ExecuteScriptFunction()
{
// m_WebBrowser is an instance of IWebBrowser2
MSHTML::IHTMLDocument2Ptr spDoc(m_WebBrowser.GetDocument());
if (spDoc)
{
IDispatchPtr spDisp(spDoc-> GetScript());
if (spDisp)
{
// Evaluate is the name of the script function.
OLECHAR FAR* szMember = L "evaluate ";
DISPID dispid;