I am building an extended webbrowser which I want to support Optical Zooming as implemented in IE7. The control base uses the VS 2005 webbrowser native control with IOleCommandTarg et COM interface implemented. Despite following MSDN docs on this it would appear that marshaling the pavIn and pavOut of the IOleCommandTarg et.Exec does not correctly handle .Net objects for passing the zoom level. Based on several docs I have reviewed it would appear that the COM object is expecting a VARIANTARG pointer. My question is this, is there a good example of this inplement in C# or VB that correctly marshals the data to the COM Interface? The follow is the COM iterface and code that I am implementing:
' Interop - IOleCommandTarg et (See MSDN - http://support.microsoft.com/?kbid=311288)
<ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
InterfaceType(C omInterfaceType .InterfaceIsIUn known)> _
Public Interface IOleCommandTarg et
Sub QueryStatus(ByR ef pguidCmdGroup As Guid, ByVal cCmds As UInt32, _
<MarshalAs(Unma nagedType.LPArr ay, SizeParamIndex: =1)> ByVal prgCmds As OLECMD, _
ByRef pCmdText As OLECMDTEXT)
Sub Exec(ByRef pguidCmdGroup As Guid, ByVal nCmdId As Long, _
ByVal nCmdExecOpt As Long, ByRef pvaIn As Object, _
ByRef pvaOut As Object)
End Interface
[code=vbnet]
Public Sub Zoom(ByVal Level As Integer)
Dim cmdt As IOleCommandTarg et
Dim oOut As New Object
Dim oIn As New Object
Dim oIE As Object = Nothing
Try
If Me.Document IsNot Nothing Then
cmdt = CType(Me.Docume nt.DomDocument, IOleCommandTarg et)
If Level < 10 Then
Level = 10
ElseIf Level > 1000 Then
Level = 1000
End If
oIn = Level
cmdt.Exec(CmdGU ID, OLECMDID.OLECMD ID_OPTICAL_ZOOM , OLECMDEXECOPT.O LECMDEXECOPT_DO DEFAULT, oIn, oOut)
End If
Catch ex As Exception
Throw New Exception(ex.Me ssage.ToString, ex.InnerExcepti on)
Finally
cmdt = Nothing
End Try
End Sub[/code]
Thanks indvance!!
Paul
' Interop - IOleCommandTarg et (See MSDN - http://support.microsoft.com/?kbid=311288)
<ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
InterfaceType(C omInterfaceType .InterfaceIsIUn known)> _
Public Interface IOleCommandTarg et
Sub QueryStatus(ByR ef pguidCmdGroup As Guid, ByVal cCmds As UInt32, _
<MarshalAs(Unma nagedType.LPArr ay, SizeParamIndex: =1)> ByVal prgCmds As OLECMD, _
ByRef pCmdText As OLECMDTEXT)
Sub Exec(ByRef pguidCmdGroup As Guid, ByVal nCmdId As Long, _
ByVal nCmdExecOpt As Long, ByRef pvaIn As Object, _
ByRef pvaOut As Object)
End Interface
[code=vbnet]
Public Sub Zoom(ByVal Level As Integer)
Dim cmdt As IOleCommandTarg et
Dim oOut As New Object
Dim oIn As New Object
Dim oIE As Object = Nothing
Try
If Me.Document IsNot Nothing Then
cmdt = CType(Me.Docume nt.DomDocument, IOleCommandTarg et)
If Level < 10 Then
Level = 10
ElseIf Level > 1000 Then
Level = 1000
End If
oIn = Level
cmdt.Exec(CmdGU ID, OLECMDID.OLECMD ID_OPTICAL_ZOOM , OLECMDEXECOPT.O LECMDEXECOPT_DO DEFAULT, oIn, oOut)
End If
Catch ex As Exception
Throw New Exception(ex.Me ssage.ToString, ex.InnerExcepti on)
Finally
cmdt = Nothing
End Try
End Sub[/code]
Thanks indvance!!
Paul