Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than ole32, prefix the name with the module name and a period.
PropStgNameToFmtId (ole32)
.
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
Dim characters As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
Dim name As String = "MyPropertyStorageName
Dim name As New StringBuilder(propertyStorageName)
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
index = characters.IndexOf(Char.ToUpper(name.Chars(i)))
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.
Guids generated with this will return the name using the FmtIdToPropStgName Function. 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
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).