How to enumerate WIC codecs?

As shown in the previous article, Windows Imaging Component (WIC) comes with built-in codecs (for BMP, JPEG, GIF, PNG, TIFF, and HDPhoto image file formats). Additionally, WIC can deal with other image formats for which appropriate codecs are installed in the system.
Basically, to list available WIC codecs and eventually get info for each one, we can do the following:

  1. Call IWICImagingFactory::CreateComponentEnumerator in order to get a component enumerator either for WIC decoders or for WIC encoders.
  2. For each element of the enumerator, get IWICBitmapCodecInfo interface.
  3. Call IWICBitmapCodecInfo::GetFriendlyName, IWICBitmapCodecInfo::GetFileExtensions and other methods in order to get codec info.

Enumerate WIC codecs

Here is a sample function, implemented as described above. First argument is a pointer to a IWICImagingFactory instance, required for creating the component enumerator. Second argument can have either WICDecoder or WICEncoder value, to retrieve WIC decoders or encoders, respectively. Finally, last argument is an ATL list containing structures to be filled with codecs info.

HRESULT CWICUtils::_EnumCodecs(IWICImagingFactory* pImagingFactory,
                               WICComponentType type,
                               CAtlList<CCodecInfo>& listCodecInfo)
   ATLASSERT((type == WICDecoder) || (type == WICEncoder));

   CComPtr<IEnumUnknown> pEnum;
   DWORD dwOptions = WICComponentEnumerateDefault;
   HRESULT hr = pImagingFactory->CreateComponentEnumerator(type, 
      dwOptions, &pEnum);
      const UINT cbBuffer = 256; // if not enough will be truncated
      ULONG cbActual = 0;
      CComPtr<IUnknown> pElement = NULL;
      while(S_OK == pEnum->Next(1, &pElement, &cbActual))
         CCodecInfo codecInfo;
         UINT cbActual = 0;
         CComQIPtr<IWICBitmapCodecInfo> pCodecInfo = pElement;
         // Codec name
         // File extensions
         //... other codec info.
         // add element to list
         pElement = NULL;
   return hr;


Enumerate WIC decoders

CWICUtils::EnumDecoders simply calls CWICUtils::_EnumCodecs passing WICDecoder value.

HRESULT CWICUtils::EnumDecoders(IWICImagingFactory* pImagingFactory,
                                CAtlList<CCodecInfo>& listCodecInfo)
   return _EnumCodecs(pImagingFactory, WICDecoder, listCodecInfo);


Enumerate WIC encoders

CWICUtils::EnumEncoders calls CWICUtils::_EnumCodecs passing WICEncoder value.

HRESULT CWICUtils::EnumEncoders(IWICImagingFactory* pImagingFactory,
                                CAtlList<CCodecInfo>& listCodecInfo)
   return _EnumCodecs(pImagingFactory, WICEncoder, listCodecInfo);


Display WIC decoders info example

This example demonstrates how to use CWICUtils::EnumDecoders to display WIC decoders info in a simple console application.

int main()
   // initialize COM
   IWICImagingFactory* pImagingFactory;

   // create IWICImagingFactory instance
   HRESULT hr = ::CoCreateInstance(CLSID_WICImagingFactory,

      CAtlList<CCodecInfo> listCodecInfo;
      // enumerate decoders
      hr = CWICUtils::EnumDecoders(pImagingFactory, listCodecInfo);
         POSITION pos = listCodecInfo.GetHeadPosition();
         while(NULL != pos)
            // dispay decoder info
            const CCodecInfo& codecInfo = listCodecInfo.GetNext(pos);
            wprintf_s(L"\nCodec name: %s\nFile extensions: %s\n",
   return hr;


      1. Include necessary ATL headers as well as WIC library headers.
        // ATL headers
        #include <atlbase.h>
        #include <atlstr.h>
        #include <atlcoll.h>
        // WIC library headers
        #include <Wincodec.h>
      2. Add Windowscodecs.lib to linker additional dependencies or use pragma comment lib as follows:
        #pragma comment(lib, "Windowscodecs.lib")
      3. Here are the definitions of CCodecInfo and CWICUtils classes:
        struct CCodecInfo
           CStringW m_strFriendlyName;
           CStringW m_strFileExtensions;
        class CWICUtils
        // ...
           static HRESULT EnumDecoders(IWICImagingFactory* pImagingFactory,
                                       CAtlList<CCodecInfo>& listCodecInfo);
           static HRESULT EnumEncoders(IWICImagingFactory* pImagingFactory,
                                       CAtlList<CCodecInfo>>& listCodecInfo);
           static HRESULT _EnumCodecs(IWICImagingFactory* pImagingFactory,
                                      WICComponentType type,
                                      CAtlList<CCodecInfo>>& listCodecInfo);
      4. The examples are intentionally made as simple as possible in order to just show how to do; you can modify and adapt them according to your particular needs.
      5. I’ve tested under Visual Studio 2008.
      6. The minimum operating system is Windows XP with SP3 or Windows XP with SP2 and redistributed WIC.


3 thoughts on “How to enumerate WIC codecs?”

    • Thank you, Cristian!
      I think it is automatically released when CComPtr object goes out of scope.
      Am I missing something more?


Leave a Comment