I am not sure it is the same. I have been trying to translate someone's
program from VS 2008 to 2003 and I am having lots of problems in the code.
See the code below. I tried converting all UShorts to UInt16, then tried
some to Integer, and nothing is working. If you have any pointers I will
appreciate it.
Imports System
Imports System.Reflection
Imports WMFSDKWrapper
Public Class MetaDataReader
' WM file
Private mediaFilename As String
' Info attributes
Public Attributes As AttributeList
' Default constructor
Public Sub New(ByVal filename As String)
' Apply incoming data
mediaFilename = filename
' Create WMF reader
Dim MetadataEditor As IWMMetadataEditor
WMFSDKFunctions.WMCreateEditor(MetadataEditor)
MetadataEditor.Open(mediaFilename)
Attributes = New AttributeList
' Get Headers version 3
Dim HeaderInfo3 As IWMHeaderInfo3 = MetadataEditor
' HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;
' Read attributes
For Each AttributeName As String In AttributeList.Attributes
'HRESULT GetAttributeByName(
' WORD* pwStreamNum,
' LPCWSTR pszName,
' WMT_ATTR_DATATYPE* pType,
' BYTE* pValue,
' WORD* pcbLength
');
Dim pwStreamNum As UShort
Dim pType As WMT_ATTR_DATATYPE
Dim pcbLength As UShort
Try
HeaderInfo3.GetAttributeByName(pwStreamNum, AttributeName,
pType, Nothing, pcbLength)
Catch ex As Exception
Return
End Try
Dim pValue(pcbLength) As Byte
HeaderInfo3.GetAttributeByName(pwStreamNum, AttributeName,
pType, pValue, pcbLength)
Dim convertedValue As String = ConvertAttrToString(pValue,
pcbLength)
' Convert Attribute to string
Attributes.SetProperty(AttributeName, convertedValue)
Next
' Close WMF reader
MetadataEditor.Close()
End Sub
' Convert attribute to string
Public Function ConvertAttrToString(ByVal pValue() As Byte, ByVal
pcbLength As UShort) As String
Dim value As String = ""
If pcbLength = 0 Then
Return value
End If
' Convert from UTF-16LE BOM+ format
If Convert.ToInt16(pValue(0)) = Convert.ToInt16("FE", 16) _
And Convert.ToInt16(pValue(0)) = Convert.ToInt16("FF", 16) Then
value = "UTF-16LE BOM+"
If (pcbLength >= 4) Then
For index As Integer = 2 To pValue.Length - 4 Step 2
value += Convert.ToString(BitConverter.ToChar(pValue,
index))
Next
End If
' Convert from UTF-16BE BOM+ format
ElseIf Convert.ToInt16(pValue(0)) = Convert.ToInt16("FF", 16) _
And Convert.ToInt16(pValue(0)) = Convert.ToInt16("FE", 16)
Then
value = "UTF-16BE BOM+"
If (pcbLength >= 4) Then
For index As Integer = 2 To pValue.Length - 4 Step 2
value += Convert.ToString(BitConverter.ToChar(pValue,
index))
Next
End If
' Convert from UTF-16BE BOM+ format
Else
value = ""
If (pcbLength >= 2) Then
For index As Integer = 0 To pValue.Length - 4 Step 2
value += Convert.ToString(BitConverter.ToChar(pValue,
index))
Next
End If
End If
Return value
End Function
End Class