列舉所有已安裝的 Windows Media 編解碼器
[與此頁面相關聯的功能 Windows Media Format 11 SDK是舊版功能。 來源讀取器和接收寫入器已取代它。 來源讀取器和接收寫入器已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用來源讀取器和接收寫入器,而不是Windows Media Format 11 SDK。 Microsoft 建議盡可能重寫使用舊版 API 的現有程式碼,以使用新的 API。]
編解碼器資訊介面全都使用編解碼器索引來識別個別編解碼器。 編解碼器會針對音訊和視訊獨立編制索引。 在一種類型的編解碼器內,索引範圍從 0 到小於該類型的編解碼器數目。
下列範例程式碼示範如何取得與每個編解碼器相關聯的索引。 若要在應用程式中編譯此程式碼,請包含 stdio.h。
HRESULT GetCodecNames(IWMCodecInfo3* pCodecInfo)
{
HRESULT hr = S_OK;
DWORD cCodecs = 0;
WCHAR* pwszCodecName = NULL;
DWORD cchCodecName = 0;
// Retrieve the number of supported audio codecs on the system.
hr = pCodecInfo->GetCodecInfoCount(WMMEDIATYPE_Audio, &cCodecs);
if(SUCCEEDED(hr))
printf("Number of audio codecs: %d\n\n", cCodecs);
else
{
printf("Could not get the count of audio codecs.\n");
return hr;
}
// Loop through all the audio codecs.
for(DWORD dwCodecIndex = 0; dwCodecIndex < cCodecs; dwCodecIndex++)
{
// Get the codec name:
// First, get the size of the name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Audio,
dwCodecIndex,
NULL,
&cchCodecName);
if(FAILED(hr))
{
printf("Could not get the size of the codec name.\n");
return hr;
}
// Allocate a string of the appropriate size.
pwszCodecName = new WCHAR[cchCodecName];
if(pwszCodecName == NULL)
{
printf("Could not allocate memory.\n");
return E_OUTOFMEMORY;
}
// Retrieve the codec name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Audio,
dwCodecIndex,
pwszCodecName,
&cchCodecName);
if(FAILED(hr))
{
delete[] pwszCodecName;
printf("Could not get the codec name.\n");
return hr;
}
// Print the codec name.
printf("%d %S\n", dwCodecIndex, pwszCodecName);
// Clean up for the next iteration.
delete[] pwszCodecName;
pwszCodecName = NULL;
cchCodecName = 0;
}
// Retrieve the number of supported video codecs on the system.
hr = pCodecInfo->GetCodecInfoCount(WMMEDIATYPE_Video, &cCodecs);
if(SUCCEEDED(hr))
printf("\n\nNumber of video codecs: %d.\n\n", cCodecs);
else
{
printf("Could not get the count of video codecs.\n");
return hr;
}
// Loop through all the video codecs.
for(dwCodecIndex = 0; dwCodecIndex < cCodecs; dwCodecIndex++)
{
// Get the codec name:
// First, get the size of the name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Video,
dwCodecIndex,
NULL,
&cchCodecName);
if(FAILED(hr))
{
printf("Could not get the size of the codec name.\n");
return hr;
}
// Allocate a string of the appropriate size.
pwszCodecName = new WCHAR[cchCodecName];
if(pwszCodecName == NULL)
{
printf("Could not allocate memory.\n");
return E_OUTOFMEMORY;
}
// Retrieve the codec name.
hr = pCodecInfo->GetCodecName(WMMEDIATYPE_Video,
dwCodecIndex,
pwszCodecName,
&cchCodecName);
if(FAILED(hr))
{
printf("Could not get the codec name.\n");
return hr;
}
// Print the codec name.
printf("%d %S\n", dwCodecIndex, pwszCodecName);
delete[] pwszCodecName;
pwszCodecName = NULL;
cchCodecName = 0;
}
return S_OK;
}
相關主題