@msdn=http://search.microsoft.com/search/results.aspx?qu=$$$ @pinvoke=http://pinvoke.net/$$$.htm Summary: The PropStgNameToFmtId API !!!!C# Signature: [DllImport("ole32.dll")] static extern int PropStgNameToFmtId([MarshalAs(UnmanagedType.LPWStr)] string oszName, out FMTID pfmtid); !!!!VB.Net Signature: <DllImport("ole32.dll", preservesig:=False)> _ Friend Shared Function PropStgNameToFmtId( _ <MarshalAs(UnmanagedType.LPWStr)> ByVal oszName As String, _ <Out()> ByRef FMTID As Guid) As Integer End Function !!!!User-Defined Types: None. !!!!Notes: None. !!!!Tips & Tricks: To generate a FormatIdentifier from a custom PropertyStorage name use the following in VB.Net: Dim characters As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345" Dim name As String = "MyPropertyStorageName Dim bits As BitArray Dim i As Integer Dim j As Integer Dim index As Integer Dim idBytes() As Byte Dim idBits As BitArray idBits = New BitArray(130) '26 * 5 - 26 Characters @ 5bits each name = name.ToUpper For i = 0 To name.Length - 1 'Get the index of the current character and convert it to 'a BitArray with a length of five (MaxValue = 31 hence the 'character restriction index = characters.IndexOf(name.Chars(i)) If index < 0 Then Throw New ApplicationException("Invalid Character") End If bits = New BitArray(New Byte() _ {CByte(index)}) For j = 0 To 4 idBits(j + (5 * i)) = bits(j) Next Next 'A new Guid requires an array of exactly 16 bytes 'Split the first 128 bits of the array into 8 bit chunks For i = 0 To 15 ReDim Preserve idBytes(i) bits = New BitArray(8) For j = 0 To 7 bits(j) = idBits(j + (8 * i)) Next idBytes(i) = CByte(BitsToInteger(bits)) Next Dim fmtId As New Guid(idBytes) Guids generated with this will return the name using the FmtIdToPropStgName Function, and can be used to generate a new IPropertyStorage interface with IPropertySetStorage.Create(). The name returned will be filled to 26 chars with the letter 'a' due to the fixed size of a Guid and the fact that we're passing all zeros in the BitArray after the name finishes to reach this size. The following helper function is also required: Friend Function BitsToInteger(ByVal bits As BitArray) As Integer Dim int As Integer = 0 Dim i As Integer For i = 0 To bits.Count - 1 If bits(i) Then int += 2 ^ i End If Next Return int End Function See Also: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stg/stg/names_in_istorage.asp !!!!Sample Code: Please add some! !!!!Alternative Managed API: Do you know one? Please contribute it! Documentation: PropStgNameToFmtId@msdn on MSDN
Edit ole32.PropStgName...
You do not have permission to change this page. If you feel this is in error, please send feedback with the contact link on the main page.