Share via


プロファイルの保存

[このページに関連付けられている機能である Windows Media Format 11 SDK は、従来の機能です。 ソース リーダーシンク ライターに置き換わりました。 ソース リーダーシンク ライターは、Windows 10とWindows 11用に最適化されています。 Microsoft では、可能であれば、新しいコードで Windows Media Format 11 SDK ではなくソース リーダーシンク ライターを使用することを強くお勧めします。 Microsoft は、レガシ API を使用する既存のコードを、可能であれば新しい API を使用するように書き換えるよう提案しています。]

IWMProfileManager::SaveProfile メソッドを使用して、プロファイル オブジェクトの内容を XML で書式設定された文字列に保存できます。 プロファイル文字列をファイルに格納するメソッドは提供されません。任意のファイル I/O ルーチンを使用できます。

注意

ファイルに書き込まれたプロファイル文字列を変更しないでください。 プロファイルに対して行う変更は、プログラムで行う必要があります。 .prx ファイルの値を変更すると、予期しない結果が発生する可能性があります。

 

次の例は、標準の C スタイルのファイル I/O を使用してプロファイルをファイルに保存する関数です。 この例を使用するアプリケーションをコンパイルするには、プロジェクトに stdio.h を含める必要があります。

HRESULT ProfileToFile(IWMProfileManager* pProfileMgr, 
                      IWMProfile* pProfile)
{
    HRESULT hr = S_OK;

    FILE*   pFile;
    
    WCHAR*  pwszProfileString = NULL;
    DWORD   cchProfileString = 0;

    // Save the profile to a string.
    // First, retrieve the size of the string required.
    hr = pProfileMgr->SaveProfile(pProfile, 
                                  NULL, 
                                  &cchProfileString);
    if(FAILED(hr))
    {
        printf("Could not get the profile string size.");
        return hr;
    }

    // Allocate memory to hold the string.
    pwszProfileString = new WCHAR[cchProfileString];

    if(pwszProfileString == NULL)
    {
        printf("Could not allocate memory for the profile string.");
        return E_OUTOFMEMORY;
    }

    // Retrieve the string.
    hr = pProfileMgr->SaveProfile(pProfile, 
                                  pwszProfileString, 
                                  &cchProfileString);
    if(FAILED(hr))
    {
        printf("Could not save the profile string.");
        return hr;
    }

    // Create the output file.
    pFile = fopen("MyProfile.prx", "w");

    // Write the profile string to the file.
    fprintf(pFile, "%S\n", pwszProfileString);

    // Close the file.
    fclose(pFile);

    delete[] pwszProfileString;

    return S_OK;
}

プロファイルの操作