Unable to get IApplicationAssociationRegistration::QueryAppIsDefault working
So I'm trying to use IApplicationAssociationRegistration, which has been introduced with Windows Vista. I am using Windows 7 x64.
However, every call that receives a ProgId (aka AppRegistryName, e.g. "FirefoxHTML") returns a HRESULT of 0x80070002 which means "The system cannot find the file specified". Calls like QueryCurrentDefault that do not need/receive a ProgId, but instead return one, work flawlessly. I'm at a complete loss of what kind of file is not being found here and I'm also out of ideas what else might be going on.
Since I'm not really into COM st开发者_Go百科uff, it may be something super stupid that I am missing here. Thanks for any advice!
Here's a screenshot: http://i.imgur.com/x62y3.png
And here's the crude isolated code for you guys to try/reproduce, don't forget to set a breakpoint:
#include <windows.h>
#include <tchar.h>
#include <shobjidl.h>
HRESULT CheckStuff(__out BOOL* pfHasDotHTM)
{
IApplicationAssociationRegistration* pAAR;
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
NULL, CLSCTX_INPROC,
__uuidof(IApplicationAssociationRegistration),
(void**)&pAAR);
if (SUCCEEDED(hr))
{
hr = pAAR->QueryAppIsDefault(L".html",
AT_FILEEXTENSION, AL_EFFECTIVE,
L"FirefoxHTML",
pfHasDotHTM);
pAAR->Release();
}
return hr;
}
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
BOOL bx = FALSE;
CheckStuff(&bx);
CoUninitialize();
return 0;
}
Update 2:
Got it!
The key is that using the ProgId as AppRegistryName is plain wrong. One needs to use the name registered in HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications!
Working example:
hr = pAAR->QueryAppIsDefault(L".html",
AT_FILEEXTENSION,
AL_EFFECTIVE,
L"Firefox",
pfHasDotHTM);
I repro (Win7 x86), I think the chief problem is that FirefoxHTML is not actually a ProgID. An essential subkey for a ProgID is the CLSID key, it points to the associated HKCR\Classes subkey. Firefox is quite COM agnostic.
精彩评论