[WinAPI] Cum aflu executabilul asociat unei extensii?

Folosire Windows API in programe C/C++ (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[WinAPI] Cum aflu executabilul asociat unei extensii?

Post by Ovidiu Cucu » 04 Aug 2010, 19:00

Intrebare
Cum aflu executabilul asociat unei extensii (".txt", ".doc", ".xls" etc)?

Raspuns
Simplu, folosind functia AssocQueryString.

Exemplu

Code: Select all

#include <shlwapi.h>
#include <tchar.h>

#pragma comment(lib, "shlwapi.lib")
//...
   LPCTSTR pszExtension = _T(".xls");
   DWORD dwSize = _MAX_PATH + 1;
   TCHAR pszAssocExe[_MAX_PATH + 1] = {0};
//...
   HRESULT hr = ::AssocQueryString(0, ASSOCSTR_EXECUTABLE, 
                                  pszExtension, _T("open"), pszAssocExe, &dwSize);
   if(SUCCEEDED(hr))
   {
      // Enjoy of pszAssocExe.
   }
//...
Vezi si
<< Back to Windows API Index



Post Reply