共用方式為


儲存檔案

[與此頁面相關聯的功能 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;
}

使用配置檔