views:

129

answers:

1

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 stuff, 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);
+1  A: 

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.

Hans Passant
Hey, thanks, but http://msdn.microsoft.com/en-us/library/bb776873%28VS.85%29.aspx and http://msdn.microsoft.com/en-us/library/bb776872%28VS.85%29.aspx do not state such a thing. :oI'll be looking into adding a GUID/CLSID though, just to see whether it changes anything.FirefoxHTML is just an example by the way, we'll be using a ProgId specific to our application.
KiNgMaR
Maybe you ought to give a better example.
Hans Passant