[与此页面关联的功能(Windows Media Format 11 SDK)是一项旧功能。 它已由源读取器和接收器编写器所取代。 源读取器 和 接收器编写器 已针对 Windows 10 和 Windows 11 进行了优化。 Microsoft 强烈建议新代码尽可能使用源代码读取器和接收器编写器,而不是 Windows Media 格式 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;
}
相关主题