how to implement IOleCommandTarget?
I have a form which uses a webbrowser. however, sometimes, the page the webbrowser browses have javascript errors. I want to filter these errors.
I know SuppressScriptError = true can filter it. but the original .net 2.0 webbrowser is extended by implementing IOleClientSite. somehow, the suppressscripterror does not work anymore (i do not why). and I need the IOleClientSite to control the images that are shown in the webbrowser.
so, I searched many days, and find that should implement IOleCommandTarget
so, here is the part
Code:
<ComVisible(True)> _
Public Class clsWebBrowserEx
Inherits System.Windows.Forms.WebBrowser
Implements IOleCommandTarget, IOleClientSite
.................
#Region "IOleCommandTarget"
Public Function QueryStatus(ByRef pguidCmdGroup As Guid, ByVal cCmds As UInt32, <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1)> ByVal prgCmds() As OLECMD, ByRef pCmdText As OLECMDTEXT) As Integer Implements IOleCommandTarget.QueryStatus
Return 0
End Function
Public Function Exec(ByRef pguidCmdGroup As Guid, ByVal nCmdId As UInt32, ByVal nCmdExecOpt As UInt32, ByRef pvaIn As Object, ByRef pvaOut As Object) As Integer Implements IOleCommandTarget.Exec
Dim OLECMDID_SHOWSCRIPTERROR As Integer = 40
Dim Ret As Integer = Nothing
Select Case (nCmdId)
Case OLECMDID_SHOWSCRIPTERROR
Ret = 0
Case Else
Ret = 1
End Select
Return Ret
End Function
#End Region
and here is the definition
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure OLECMDTEXT
Public cmdtextf As UInt32
Public cwActual As UInt32
Public cwBuf As UInt32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> _
Public rgwz As Char
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure OLECMD
Public cmdID As UInt32
Public cmdf As UInt32
End Structure
<ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleCommandTarget
<PreserveSig()> Function QueryStatus(ByRef pguidCmdGroup As Guid, ByVal cCmds As UInt32, <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1)> ByVal prgCmds() As OLECMD, ByRef pCmdText As OLECMDTEXT) As Integer
<PreserveSig()> Function Exec(ByRef pguidCmdGroup As Guid, ByVal nCmdId As UInt32, ByVal nCmdExecOpt As UInt32, ByRef pvaIn As Object, ByRef pvaOut As Object) As Integer
End Interface
but, for some reasons, the exec is never fired. so, the script error keeps poping up. I could not figure out why from what I searched. anyone has an idea?
thanks
bear