I am trying to get at comment data in a Metafile that has been dragDrop'd onto my form, however, this code generates the error:
Additional Information: The runtime has encountered a fatal error. The address of the error was at 0xeb556610, on thread 0x2080. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Every code example I've seen talks about getting the image from the Metafile instead of the metafile itself. The error occurs on the "Dim mf = Metafile" in the DragDrop handler, it never gets to the enumeration code.
Private Sub Form1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent(DataFormats.EnhancedMetafile, False) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub Form1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
If e.Data.GetDataPresent(DataFormats.EnhancedMetafile, False) Then
Dim mf As Metafile = e.Data.GetData(DataFormats.EnhancedMetafile, False)
Me.CreateGraphics().EnumerateMetafile(mf, New Point(0, 0), New Graphics.EnumerateMetafileProc(AddressOf MetafileCallback))
End If
End Sub
Private Function MetafileCallback(ByVal recordType As EmfPlusRecordType, ByVal flags As Integer, ByVal dataSize As Integer, ByVal data As IntPtr, ByVal callbackData As PlayRecordCallback) As Boolean
If recordType = EmfPlusRecordType.Comment Then
Debug.WriteLine("Got comment")
End If
End Function
Short answer: You can't dragDrop a metafile. You just can't. You can, however, put it on the clipboard and get it there with User32.dll magic.
Here's both the get and put code: