Share via


IWMSBufferAllocator::AllocatePageSizeBuffer

banner art

Previous Next

IWMSBufferAllocator::AllocatePageSizeBuffer

The AllocatePageSizeBuffer method initializes a page-aligned INSSBuffer object.

Syntax

  HRESULT AllocatePageSizeBuffer(
  DWORD  dwMaxBufferSize,
  INSSBuffer**  ppBuffer
);

Parameters

dwMaxBufferSize

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

ppBuffer

[out] Pointer to a pointer to an INSSBuffer interface.

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Return code Number Description
E_INVALIDARG 0x80070057 One or both parameters are not valid.
E_OUTOFMEMORY 0x8007000E The method failed to allocate memory.
E_UNEXPECTED 0x8000FFFF The dwMaxBufferSize parameter equals zero (0).

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.

HRESULT STDMETHODCALLTYPE 
CSDKSamplePlaylistParser::WritePlaylist( 
                        IXMLDOMDocument *pPlayList,
                        IWMSPlaylistParserCallback *pCallback,
                        QWORD qwContext)
{
    IXMLDOMNode           *pAttrNode, *pNode;
    IXMLDOMNodeList       *pNodeList;
    IXMLDOMNamedNodeMap   *pNodeAttr;
    IWMSBufferAllocator   *pBufAllocator;
    INSSBuffer            *pBuffer;
    CComBSTR               bstrAttrName, bstrAttrValue, bstrTemp;
    CComVariant            varValue;
    int                    i, j;
    long                   lLength, lLength2;
    HRESULT                hr;

    bstrTemp = "media";
    hr = pPlayList->getElementsByTagName(bstrTemp, &pNodeList);
    if (FAILED(hr)) goto EXIT;

    hr = pNodeList->get_length(&lLength);
    if (FAILED(hr)) goto EXIT;

    bstrTemp = "";
    for (i=0; i < lLength; i++)
    {
        hr = pNodeList->get_item((long)i, &pNode);
        if (FAILED(hr)) goto EXIT;

        hr = pNode->get_attributes(&pNodeAttr);
        if (FAILED(hr)) goto EXIT;

        hr = pNodeAttr->get_length(&lLength2);
        if (FAILED(hr)) goto EXIT;

        for (j=0; j < lLength2; j++)
        {
            hr = pNodeAttr->get_item((long)j, &pAttrNode);
            if (FAILED(hr)) goto EXIT;
            hr = pAttrNode->get_nodeName(&bstrAttrName);
            if (FAILED(hr)) goto EXIT;

            if( bstrAttrName == "src" )
            {
                hr = pAttrNode->get_nodeValue(&varValue);
                if (FAILED(hr)) goto EXIT;

                bstrTemp.Append(varValue.bstrVal);
                bstrTemp.Append("\r\n");
                break;
            }
        }
    }

    if( bstrTemp.ByteLength() > 0 )
    {
        m_spClassFactory.QueryInterface(&pBufAllocator);
        pBufAllocator->AllocatePageSizeBuffer(bstrTemp.ByteLength(),
                                              &pBuffer);

        BYTE *pBuf;
        pBuffer->SetLength(bstrTemp.ByteLength());
        pBuffer->GetBuffer(&pBuf);
        memcpy(pBuf, (char *)bstrTemp.m_str, bstrTemp.ByteLength());

        hr = S_OK;
        pCallback->OnWritePlaylist(hr, pBuffer, qwContext);
        return( hr );
    }

EXIT:
    // TODO: Release temporary COM objects.
    return( hr );
}

Requirements

Header: wmsbuffer.h.

Library: WMSServerTypeLib.dll.

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

See Also

Previous Next