Share via


IWMSBufferAllocator.AllocateBuffer (C#)

banner art

Previous Next

IWMSBufferAllocator.AllocateBuffer (C#)

The AllocateBuffer method initializes an INSSBuffer object.

Syntax

  

Parameters

dwMaxBufferSize

uint 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 container 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

This method is used internally mainly by media parser, data sink, and data source plug-ins. Custom plug-in applications include, but are not limited to, data source and cache proxy plug-ins.

Example Code

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

void IWMSPlaylistParser.WritePlaylist(
    IXMLDOMDocument pPlaylist,
    IWMSPlaylistParserCallback pCallback,
    ulong qwContext)
{
    IXMLDOMNodeList NodeList;
    IWMSBufferAllocator pBufAlloc;
    INSSBuffer pINSSBuffer = null;
    string strPls;
    string strMedia = "";
    IntPtr pBuf;
    int i;
    int j;
    Encoder Enc = Encoding.Unicode.GetEncoder();
    byte[] Bytes;
    int iBytes;

    try
    {
        strPls = "!- DJ_FILE v1.0 -!\r\n";

        NodeList = pPlaylist.getElementsByTagName("media");
        for( i = 0; i < NodeList.length; i++ )
        {
            for( j = 0; j < NodeList[i].attributes.length; j++ )
            {
                if( NodeList[i].attributes[j].nodeName == "src" )
                    strMedia =
                          (string)NodeList[i].attributes[j].nodeValue;
                else
                    strPls = strPls + "# " +
                           NodeList[i].attributes[j].nodeName + "=\"" +
                           NodeList[i].attributes[j].nodeValue + "\"\r\n";
            }
            if( !strMedia.Equals("") )
                strPls = strPls + strMedia + "\r\n\r\n";
        }

        iBytes = Enc.GetByteCount(strPls.ToCharArray(), 0, strPls.Length,
                                  false);
        Bytes = (byte[])Array.CreateInstance(typeof(byte), iBytes);
        iBytes = Enc.GetBytes(strPls.ToCharArray(), 0, strPls.Length,
                              Bytes, 0, true);

        pBufAlloc = (IWMSBufferAllocator)m_ClassFactory;
        pBufAlloc.AllocateBuffer(Convert.ToUInt32(iBytes),
                                 out pINSSBuffer);
        pINSSBuffer.SetLength(Convert.ToUInt32(iBytes));
        pINSSBuffer.GetBuffer(out pBuf);

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

        pCallback.OnWritePlaylist(S_OK, pINSSBuffer, qwContext);
    }
    catch
    {
        pCallback.OnWritePlaylist(E_FAIL, pINSSBuffer, qwContext);
    }
}

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