Assertion Failed (trying to call JavaScript function)

Hi guys,

I am trying to call a JavaScript function, but I got an error which said Debug Assetion Failed, anyone able to help me out please?

Here's the function:

// CCustomModalDialog ExecuteScriptFunction

void CCustomModalDialog::ExecuteScriptFunction()
  // m_WebBrowser is an instance of IWebBrowser2
  MSHTML::IHTMLDocument2Ptr spDoc(m_browser.GetDocument());

  if (spDoc)
     IDispatchPtr spDisp(spDoc->GetScript());
     if (spDisp)
        // Evaluate is the name of the script function.
        OLECHAR FAR* szMember = L"evaluate";
        DISPID dispid;

        HRESULT hr = spDisp->GetIDsOfNames(IID_NULL, &szMember, 1,
                                       LOCALE_SYSTEM_DEFAULT, &dispid);

        if (SUCCEEDED(hr))
           COleVariant vtResult;
           static BYTE parms[] = VTS_BSTR;

           COleDispatchDriver dispDriver(spDisp, FALSE);

           dispDriver.InvokeHelper(dispid, DISPATCH_METHOD, VT_VARIANT,
                                   (void*)&vtResult, parms,

Who is Participating?
mahesh1402Connect With a Mentor Commented:
Because I think your browser is not having piece of javascript code with 'evaluate' function. Note that 'evaluate' is custom javascript function which calls javascript eval() function as per this article :

your brwoser should have following piece of HTML code :


      function evaluate(x)
         return eval(x)


Cyber-DrugsAuthor Commented:
I tested the code on the following page and still get the Assertion erorr:

                  function evaluate(x)
         return eval(x);
                  function ExitSystem ()
                        window.external.CB_CallJS(); // Calls ExecuteScriptFunction()
            <input type='button' value='click me' onclick='ExitSystem();' />
Cyber-DrugsAuthor Commented:
Just a thought, but do I maybe need to tell it the name of the Web Browser Element on my C++ Form?
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Webbrowser control 'm_browser' should have above piece of HTML code.
Cyber-DrugsAuthor Commented:
That's the right one...

Want me to upload the project to and maybe you can see what is going wrong?
Cyber-DrugsAuthor Commented:
I just ran a debug, and it's falling over on this line:

MSHTML::IHTMLDocument2Ptr spDoc(m_browser.GetDocument());
Cyber-DrugsAuthor Commented:
Just added an if statement on m_browser, and it seems it doesn't exist...

How would I go about populating it with whatever it needs?
Cyber-DrugsAuthor Commented:
I did a check, and it is being declared:

      enum { IDD = IDD_MODAL_DIALOG };
      CWebBrowser2      m_browser;

It's just not working, I think if I can get it to work, then the JavaScript call will work. Ideas please?
Cyber-DrugsAuthor Commented:
OK fixed it!!

It was something extremely stupid...

some pages were m_browser and others were m_Browser

Once I standardized that, it worked!!!!

Cheers mahesh1402 !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.