Thanks again! I'm only interested in the original filenames of objects embedded as icons anyway, so this will be great. I got my code for parsing the filename out of the metafile working. In case its of anyhelp to you, I've pasted it below. Its an adaptation of the sample code for the EnumerateMetafileProc documentation in the .Net online help.
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports System.Text
Public Class MetafileParser
Private metafile1 As Metafile
Private metafileDelegate As Graphics.EnumerateMetafileProc
Private destPoint As Point
Private MetafileText As String = ""
Public Function GetMetafileText(ByVal wmf As Metafile) As String
metafile1 = wmf
MetafileText = ""
metafileDelegate = New Graphics.EnumerateMetafileProc(AddressOf MetafileCallback)
destPoint = New Point(20, 10)
Dim G As Graphics
Dim bmp As New Bitmap(metafile1)
G = Graphics.FromImage(bmp)
G.EnumerateMetafile(metafile1, destPoint, metafileDelegate)
Return MetafileText
End Function
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
Dim Record As String
Dim dataArray As Byte() = Nothing
If data <> IntPtr.Zero Then
' Copy the unmanaged record to a managed byte buffer
' that can be used by PlayRecord.
dataArray = New Byte(dataSize) {}
Marshal.Copy(data, dataArray, 0, dataSize)
End If
Dim X As Integer = 0
Dim VectorCommand As String = ""
Dim sb As New StringBuilder
Dim c As Char
If recordType = EmfPlusRecordType.WmfExtTextOut Then
For X = dataArray.GetLowerBound(0) To dataArray.GetUpperBound(0)
If dataArray(X) > 31 Then 'And dataArray(X) < 127 Then
'Debug.Print(dataArray(X).ToString & " - " & Chr(dataArray(X)) & vbCrLf)
c = Chr(dataArray(X))
sb.Append(c)
End If
Next
Record = sb.ToString
Debug.Print(Record)
If Record.StartsWith("""fB") Then
Record = Record.Substring(3)
ElseIf Record.StartsWith("/fB") Then
Record = Record.Substring(3)
ElseIf Record.StartsWith("$fB") Then
Record = Record.Substring(3)
ElseIf Record.StartsWith("/*fB") Then
Record = Record.Substring(4)
ElseIf Record.StartsWith("/'fB") Then
Record = Record.Substring(4)
End If
If Record.Contains(Chr(34)) Then
Record = Record.Replace(Chr(34), "")
End If
MetafileText = MetafileText & Record
End If
metafile1.PlayRecord(recordType, flags, dataSize, dataArray)
Return True
End Function
End Class