IWMSBufferAllocator.AllocatePageSizeBuffer (Visual Basic .NET)

The AllocatePageSizeBuffer method initializes a page-aligned INSSBufferINSSBuffer Object (Visual Basic .NET).

IWMSBufferAllocator.AllocatePageSizeBuffer(  dwMaxBufferSize As UInt32,
  ByRef ppBuffer As INSSBuffer


Uint32 containing the maximum size of the buffer in bytes. This must be less than 16 MB (16,777,216 bytes).

Reference to an INSSBuffer object containing the buffer.

Return Value

This method does not return a value.

If this method fails, it throws an exception.




dwMaxBufferSize is greater than 16 MB or ppBuffer is null.


There is insufficient memory to complete the function.


The AllocatePageSizeBuffer method allocates page-aligned memory. Because the method is not aware of the sector size of different storage systems, it allocates a buffer of the size passed in, if possible. Therefore, it is up to the caller to determine an appropriate buffer size.


The following example uses the IWMSBufferAllocator object to allocate a buffer to hold the written playlist file.

Public Sub WritePlaylist( _
    ByVal pPlaylist As interop_msxml.IXMLDOMDocument, _
    ByVal pCallback As IWMSPlaylistParserCallback, _
    ByVal qwContext As System.UInt64) _
    Implements IWMSPlaylistParser.WritePlaylist

    Dim NodeList As IXMLDOMNodeList
    Dim pBufAlloc As IWMSBufferAllocator
    Dim pINSSBuffer As INSSBuffer
    Dim strPls As String
    Dim strMedia As String
    Dim pBuf As IntPtr
    Dim i As Integer
    Dim j As Integer
    Dim Enc As Encoder = Encoding.Unicode.GetEncoder()
    Dim Bytes As Byte()
    Dim iBytes As Integer

        strPls = "!- DJ_FILE v1.0 -!" & vbCrLf

        NodeList = pPlaylist.getElementsByTagName("media")
        For i = 0 To (NodeList.length - 1)
            For j = 0 To (NodeList(i).attributes.length - 1)
                If NodeList(i).attributes(j).nodeName = "src" Then
                    strMedia = NodeList(i).attributes(j).nodeValue
                    strPls = strPls & "# " & _
                      NodeList(i).attributes(j).nodeName & "=" & _
                      Chr(34) & NodeList(i).attributes(j).nodeValue & _
                      Chr(34) & vbCrLf
                End If
            If Not strMedia = vbNullString Then
                strPls = strPls & strMedia & vbCrLf
            End If

        iBytes = Enc.GetByteCount(strPls.ToCharArray(), 0, strPls.Length, False)
        Bytes = Array.CreateInstance(GetType(Byte), iBytes)
        iBytes = Enc.GetBytes(strPls.ToCharArray(), 0, strPls.Length, _
                              Bytes, 0, True)

        pBufAlloc = m_ClassFactory
        pBufAlloc.AllocatePageSizeBuffer(Convert.ToUInt32(iBytes), _

        Marshal.Copy(Bytes, 0, pBuf, iBytes)

        pCallback.OnWritePlaylist(S_OK, pINSSBuffer, qwContext)
    Catch e As Exception
        pCallback.OnWritePlaylist(E_FAIL, pINSSBuffer, qwContext)
    End Try
End Sub


Reference: Add a reference to Microsoft.WindowsMediaServices.

Namespace: Microsoft.WindowsMediaServices.Interop.

Assembly: Microsoft.WindowsMediaServices.dll.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also


IWMSBufferAllocator Object (C#)