Solved

Assertion Failed (trying to call JavaScript function)

Posted on 2006-11-28
9
381 Views
Last Modified: 2013-11-20
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
Comment
Question by:Cyber-Drugs
  • 7
  • 2
9 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 500 total points
ID: 18034611
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18036427
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18036556
Just a thought, but do I maybe need to tell it the name of the Web Browser Element on my C++ Form?
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 18037021
Webbrowser control 'm_browser' should have above piece of HTML code.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18037079
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18037519
I just ran a debug, and it's falling over on this line:


MSHTML::IHTMLDocument2Ptr spDoc(m_browser.GetDocument());
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18037585
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18037899
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
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18038127
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 170
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 88
sumDigits challenge 9 120
pre4 challenge 19 93
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now