How to find the application associated with particular file extension.

30 05 2008

Did you ever noticed that, While starting up some media player applications, they says that – “Some of its proprietary file formats are not associated with it and do you want to associate now?”. How these application are checking the associated application of particular filetype?

For a given file extension, you can find the executable associated with it by calling the api – AssocQueryString(). See the sample code snippet below.

#include "Shlwapi.h"
TCHAR tchApplicationPath[ MAX_PATH ] = { 0 };
HRESULT hr = AssocQueryString( 0,
                               _T( ".mp3" ),
                               _T( "open" ),
                              &dwSize );

if( FAILED( hr ))
    // Failed to get the associated application.

So next time while starting, check whether your file formats are associated with your appliaction itself. 😉 BTW, don’t forget to add Shlwapi.lib to your project settings.

Targeted Audience – Beginners.