[COM] Cum aflu executabilul asociat unei extensii?

Despre MFC, ATL si alte biblioteci C++ de la Microsoft (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[COM] Cum aflu executabilul asociat unei extensii?

Post by Ovidiu Cucu » 04 Aug 2010, 18:42

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

Raspuns
Se pot folosi metodele interfetei IQueryAssociations.

Exemplu

Code: Select all

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

#pragma comment(lib, "shlwapi.lib")
//...
   LPCTSTR pszExtension = _T(".doc");
   DWORD dwSize = _MAX_PATH + 1;
   TCHAR pszAssocExe[_MAX_PATH + 1] = {0};

   IQueryAssociations *passoc = NULL;
   HRESULT hr = ::AssocCreate(CLSID_QueryAssociations, IID_PPV_ARGS(&passoc));
   if(SUCCEEDED(hr))
   {
      hr = passoc->Init(0, pszExtension, NULL, NULL);
      if(SUCCEEDED(hr))
      {
         hr = passoc->GetString(0, ASSOCSTR_EXECUTABLE, 
                                   _T("open"), pszAssocExe, &dwSize);
         if(SUCCEEDED(hr))
         {
            // Enjoy of pszAssocExe.
         }
      }
   }
//...
Vezi si



Post Reply