Exemple #1
0
HRESULT CMixerControl::LoadControl(XMLEl* pLibrary)
{
    XMLEl* pThis = 0;
    CCString sValues;
    PCWSTR wszCurrent = 0;// Current place in the sValues string.
    WCHAR* wszToken = 0;// The token.  To avoid a buffer-overrun we make this string the same size as sValues.
    int i = 0;// Current index we're workin on.

    MIXERCONTROLDETAILS_BOOLEAN* pBoolean = (MIXERCONTROLDETAILS_BOOLEAN*)m_pRaw;
    MIXERCONTROLDETAILS_UNSIGNED* pUnsigned = (MIXERCONTROLDETAILS_UNSIGNED*)m_pRaw;
    MIXERCONTROLDETAILS_SIGNED* pSigned = (MIXERCONTROLDETAILS_SIGNED*)m_pRaw;

    if(FAILED(GetNode(0, pLibrary, &pThis, FALSE)))
    {
        return MIX_E_XMLERR;
    }

    // Here, we concern ourself with the value attribute.
    if(FAILED(XMLGetAttribute(pThis, CCString(L"Values"), &sValues)))
    {
        SAFE_RELEASE(pThis);
        return MIX_E_XMLERR;
    }

    // Let's go case-insensitive.
    sValues.upr();

    // If we're doing raw binary data, we can skip all the parsing.
    if(m_DataType == MIXDT_CUSTOM)
    {
        sValues.ToBinary(m_pRaw, m_mc.Metrics.cbCustomData);
        SAFE_RELEASE(pThis);
        return S_OK;
    }

    // Set up our looping stuff.
    wszCurrent = sValues;
    wszToken = (WCHAR*)malloc((wcslen(wszCurrent)+1)*sizeof(WCHAR));

    while(1)
    {
        wszCurrent = NextToken(wszToken, wszCurrent);

        if(m_DataType == MIXDT_BOOLEAN)
        {
            // Now wszToken is the current token.
            if(wcsicmp(wszToken, L"TRUE") == 0)
            {
                pBoolean[i].fValue = TRUE;
            }
            else if(wcsicmp(wszToken, L"FALSE") == 0)
            {
                pBoolean[i].fValue = FALSE;
            }
        }
        else if(m_DataType == MIXDT_SIGNED)
        {
            pSigned[i].lValue = wcstol(wszToken, 0, 10);
        }
        else if(m_DataType == MIXDT_UNSIGNED)
        {
            pUnsigned[i].dwValue = wcstoul(wszToken, 0, 10);
        }

        i++;

        if(i >= m_nRawItems) break;
        if(wszCurrent == 0) break;
    }

    free(wszToken);
    wszToken = 0;

    SAFE_RELEASE(pThis);

    // Now commit the buffer.
    _CommitRawBuffer();

    return S_OK;
}