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"
...
DWORD dwSize = MAX_PATH;
TCHAR tchApplicationPath[ MAX_PATH ] = { 0 };
HRESULT hr = AssocQueryString( 0,
                               ASSOCSTR_EXECUTABLE,
                               _T( ".mp3" ),
                               _T( "open" ),
                              tchApplicationPath,
                              &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.


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: