Hi Peter
Below is code (in VB.NET) that does the job. Hopefully, it will be straight
forward to convert. The function to call is GetBlockFormats(), which returns
a string array.
<code>
<StructLayout(LayoutKind.Explicit)> _
Public Class OLEVARIANT
<FieldOffset(0)> Public vt As System.Int16
<FieldOffset(2)> Public wReserved1 As System.Int16
<FieldOffset(4)> Public wReserved2 As System.Int16
<FieldOffset(6)> Public wReserved3 As System.Int16
<FieldOffset(8)> Public lVal As Integer
<FieldOffset(8)> Public iVal As Short
<FieldOffset(8)> Public bstrVal As IntPtr
<FieldOffset(8)> Public pUnkVal As IntPtr
<FieldOffset(8)> Public pArray As IntPtr
<FieldOffset(8)> Public pvRecord As IntPtr
<FieldOffset(12)> Public pRecInfo As IntPtr
Public Sub Clear()
VariantClear(Me)
End Sub 'Clear
Public Sub LoadString(ByVal Value As String)
bstrVal = Marshal.StringToBSTR(Value)
End Sub
Public Function ToNativeObject() As Object
Dim p As IntPtr
Try
'Allocate a buffer to hold the data in this OLEVARIANT
p = Marshal.AllocCoTaskMem(Marshal.SizeOf(Me.GetType() ))
Marshal.StructureToPtr(Me, p, False)
Return Marshal.GetObjectForNativeVariant(p)
Finally
'Called no matter what
Marshal.FreeCoTaskMem(p)
End Try
End Function
<DllImport("Oleaut32.dll", PreserveSig:=False)> _
Private Shared Sub VariantClear(ByVal var As OLEVARIANT)
' Leave this blank. Call will be redirected to external DLL.
End Sub
End Class 'OLEVARIANT
Public Function GetBlockFormats() As String()
Dim oleVar As OLEVARIANT
Dim obj As Object
Dim fmts As String()
oleVar = GetCommand(MSHTMLCommandEnum.IDM_GETBLOCKFMTS)
'IE doesn't return a "well-formed" VARIANT here so
'Or in the VT_BSTR flag:
oleVar.vt = CType(oleVar.vt Or VarEnum.VT_BSTR, Short)
'This is a little wrapper to call
Marshal.GetObjectForNativeVariant()
obj = oleVar.ToNativeObject()
'Cleanup the Native Variant to avoid a memory leak
oleVar.Clear()
fmts = CType(obj, String())
' Return the block formats
Return fmts
End Sub
Private Function GetCommand(ByVal cmdID As MSHTMLCommandEnum) As
OLEVARIANT
Dim oOut As New OLEVARIANT
Dim oIn As OLEVARIANT
Dim cmdt As IOleCommandTarget
Try
cmdt = DirectCast(Document, IOleCommandTarget)
cmdt.Exec(CGID_MSHTML, cmdID, OLECMDEXECOPT_DONTPROMPTUSER, oIn,
oOut)
Catch ex As Exception
Throw New Exception("ExecCommand: " & ex.Message)
End Try
Return oOut
End Function
</code>
HTH
Charles
"Peter Zentner" <peter@_REM_zentner-online.de> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
Hi,
how can I get the available block formats from the mshtml with
IDM_GETBLOCKFMTS? I'm pretty confused how to call the
IOleCommandTarget.Exec correctly. Can someone please provide me a small code snippet?
TIA
Peter