Interop(?) Problem returning bool from C# to WebBrowser Script Error handler

J

John Constant

Using the MS C++ Example
http://support.microsoft.com/default.aspx?scid=kb;en-us;261003 I've
successfully managed to trap and log Script Errors that are generated by the
WebBrowser (IE 6) which is hosted by a C# application, see below. However
I've completely failed to force the browser to continue processing script
which *should* be controlled by returning a true VT_BOOL via pvaOut. I've
tried returning bool, System.Boolean even constructing a Variant object with
various Marshalling options but without any success. Any help or suggestions
on what to try next would be much appreciated.

Thanks in advance for any help


John

void IOleCommandTarget.Exec(int pguidCmdGroup,
MsHtmlCustomization.OLECMDID nCmdID,

MsHtmlCustomization.OLECMDEXECOPT nCmdexecopt,

ref object pvaIn,

ref object pvaOut) {

if(pguidCmdGroup == 0) return;

switch((int) nCmdID) {

case 0x28: // OLECMDID_SHOWSCRIPTERROR

bool DisplayError = true; // Display Standard IE Script Error Dialog

bool ContinueRunningScripts = true; // Continue to run Scripts

HTMLDocumentClass Doc = (HTMLDocumentClass) pvaIn;

IHTMLEventObj2 ev = (IHTMLEventObj2) Doc.parentWindow.@event;

int errorLine = (int) ev.getAttribute("errorLine", 0);

string errorCharacter = ev.getAttribute("errorCharacter",
0).ToString();

int errorCode = (int) ev.getAttribute("errorCode", 0);

string errorMessage = (string) ev.getAttribute("errorMessage", 0);

string errorUrl = (string) ev.getAttribute("errorUrl", 0);

if(eScriptError != null) {

DisplayError = eScriptError(this, errorUrl, errorLine,
errorMessage, out ContinueRunningScripts);

// If were not displaying an error message then pause a moment

if(!DisplayError) Sleep(2000);

}

pvaOut = (System.Boolean) ContinueRunningScripts;

throw new COMException("", (DisplayError ? S_ERROR : S_OK));

}

return;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top