儲存設定檔
[與此頁面相關聯的功能 Windows Media Format 11 SDK是舊版功能。 來源讀取器和接收寫入器已取代它。 來源讀取器和接收寫入器已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用來源讀取器和接收寫入器,而不是Windows 媒體格式 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;
}
相關主題