• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

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,
                                   "5+Math.sin(9)");
        }
     }
  }
}

Cheers!
0
Cyber-Drugs
Asked:
Cyber-Drugs
  • 7
  • 2
1 Solution
 
mahesh1402Commented:
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 : http://support.microsoft.com/kb/q185127/

your brwoser should have following piece of HTML code :

<HTML>
  <HEAD>
    <TITLE>Evaluate</TITLE>

    <SCRIPT>
      function evaluate(x)
      {
         alert("hello")
         return eval(x)
      }
   </SCRIPT>
  </HEAD>

  <BODY>
  </BODY>
</HTML>


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



<html>
      <head>
            <script>
                  function evaluate(x)
      {
         alert("hello");
         return eval(x);
      }
            
                  function ExitSystem ()
                  {
                        window.external.CB_CallJS(); // Calls ExecuteScriptFunction()
                  }
            </script>
      </head>
      <body>
            <input type='button' value='click me' onclick='ExitSystem();' />
      </body>
</html>
0
 
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?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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

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


MSHTML::IHTMLDocument2Ptr spDoc(m_browser.GetDocument());
0
 
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?
0
 
Cyber-DrugsAuthor Commented:
I did a check, and it is being declared:


      //{{AFX_DATA(CCustomModalDialog)
      enum { IDD = IDD_MODAL_DIALOG };
      CWebBrowser2      m_browser;
      //}}AFX_DATA



It's just not working, I think if I can get it to work, then the JavaScript call will work. Ideas please?
0
 
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 !
0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now