다음을 통해 공유


복잡한 메타데이터 특성 사용

[이 페이지와 연결된 기능인 Windows Media Format 11 SDK는 레거시 기능입니다. 원본 판독기 및 싱크 작성기에 의해 대체되었습니다. 원본 판독기 및 싱크 작성기는 Windows 10 및 Windows 11 최적화되었습니다. 가능한 경우 새 코드에서 Windows Media Format 11 SDK 대신 소스 판독기 및 싱크 기록기를 사용하는 것이 좋습니다. 가능한 경우 레거시 API를 사용하는 기존 코드를 다시 작성하여 새 API를 사용하도록 제안합니다.]

Windows Media Format SDK는 구조체로 표시되는 값이 있는 특성인 복잡한 메타데이터 특성을 지원합니다. 모든 특성에는 WMT_ATTR_DATATYPE 열거형에 정의된 데이터 형식이 있어야 하므로 모든 복잡한 메타데이터 특성은 WMT_TYPE_BINARY 처리됩니다. 복합 특성을 작성할 때는 구조체에 대한 포인터를 바이트 포인터로 캐스팅합니다. 복잡한 특성을 검색할 때 IWMHeaderInfo3::GetAttributeByIndexEx 에서 설정한 바이트 배열을 적절한 구조로 캐스팅합니다.

다음 코드 예제에서는 복잡한 메타데이터 특성을 설정하고 검색하는 방법을 보여 줍니다. 첫 번째 함수는 사용자 텍스트 특성을 추가하고 두 번째 함수는 사용자 텍스트 특성을 검색합니다. 이러한 예제를 사용하는 방법에 대한 자세한 내용은 코드 예제 사용을 참조하세요.

HRESULT AddText(IWMHeaderInfo3* pHeaderInfo, 
                WCHAR* pwszDesc, 
                WCHAR* pwszText, 
                WORD* pwIndex)
{
    HRESULT hr         = S_OK;
    WORD    wIndex     = 0;
    
    WM_USER_TEXT textStruct;
    
    // Populate the text structure.
    textStruct.pwszDescription = pwszDesc;
    textStruct.pwszText = pwszText;

    // Add the attribute.
    hr = pHeaderInfo->AddAttribute(0, 
                                   g_wszWMText, 
                                   &wIndex, 
                                   WMT_TYPE_BINARY, 
                                   0, 
                                   (BYTE*)&textStruct, 
                                   sizeof(WM_USER_TEXT));

    // Pass the index of the text attribute back to the caller.
    if(SUCCEEDED(hr))
    {
        *pwIndex = wIndex;
    }
    
    return hr;
}

HRESULT DisplayText(IWMHeaderInfo3* pHeaderInfo, WORD wIndex)
{
    HRESULT hr = S_OK;

    WCHAR*  pwszName = NULL;
    WORD    cchName  = 0;
    WORD    Language = 0;
    BYTE*   pbValue  = NULL;
    DWORD   cbValue  = 0;
    

    WM_USER_TEXT*     pText    = NULL;
    WMT_ATTR_DATATYPE AttType;

    
    // Find the lengths of the attribute name and value.
    hr = pHeaderInfo->GetAttributeByIndexEx(0, 
                                            wIndex, 
                                            NULL, 
                                            &cchName, 
                                            NULL, 
                                            NULL, 
                                            NULL, 
                                            &cbValue);
    GOTO_EXIT_IF_FAILED(hr);

    // Allocate memory for the name and value.
    pwszName = new WCHAR[cchName];
    pbValue  = new BYTE[cbValue];
    
    if(pwszName == NULL || pbValue == NULL)
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    // Get the attribute.
    hr = pHeaderInfo->GetAttributeByIndexEx(0, 
                                            wIndex, 
                                            pwszName, 
                                            &cchName, 
                                            &AttType, 
                                            &Language, 
                                            pbValue, 
                                            &cbValue);
    GOTO_EXIT_IF_FAILED(hr);

    // Make sure the attribute is WM/Text, as expected.
    if(wcscmp(pwszName, g_wszWMText))
    {
        // Somehow we got the wrong attribute.
        hr = E_UNEXPECTED;
        goto Exit;
    }

    // Set the structure pointer to the retrieved value.
    pText = (WM_USER_TEXT*) pbValue;

    // Print the strings from the structure.
    printf("Description : %S\n", pText->pwszDescription);
    printf("Text        : %S\n", pText->pwszText);

Exit:
    SAFE_ARRAY_DELETE(pwszName);
    SAFE_ARRAY_DELETE(pbValue);
    return hr;
}

메타데이터 작업