IWMSBufferAllocator.AllocatePageSizeBuffer (Visual Basic .NET)

banner art

Previous Next

IWMSBufferAllocator.AllocatePageSizeBuffer (Visual Basic .NET)

The AllocatePageSizeBuffer method initializes a page-aligned INSSBuffer object.

Syntax

  

Parameters

dwMaxBufferSize

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

ppBuffer

Reference to an INSSBuffer object containing the buffer.

Return Values

This method does not return a value.

If this method fails, it throws an exception.

Number Description
0x80070057 dwMaxBufferSize is greater than 16 MB or ppBuffer is null.
0x8007000E There is insufficient memory to complete the function.

Remarks

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.

Example Code

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

    Try
        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
                Else
                    strPls = strPls & "# " & _
                      NodeList(i).attributes(j).nodeName & "=" & _
                      Chr(34) & NodeList(i).attributes(j).nodeValue & _
                      Chr(34) & vbCrLf
                End If
            Next
            If Not strMedia = vbNullString Then
                strPls = strPls & strMedia & vbCrLf
            End If
        Next

        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), _
                                         pINSSBuffer)
        pINSSBuffer.SetLength(Convert.ToUInt32(iBytes))
        pINSSBuffer.GetBuffer(pBuf)

        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

Requirements

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

Previous Next