How to tell if there's no default file extension association on OS post-Windows XP?

孤街浪徒 提交于 2019-12-05 19:14:18
c00000fd

I think I got it. The trick was to use the correct flags. This seems to work from XP and up:

WCHAR wbuffPath[MAX_PATH] = {0};
DWORD dwszBuffPath = MAX_PATH;
HRESULT hR = ::AssocQueryStringW(ASSOCF_INIT_IGNOREUNKNOWN, 
    ASSOCSTR_EXECUTABLE,
    L".weirdassextension",
    NULL,
    wbuffPath,
    &dwszBuffPath);

if(hR == 0x80070483)   // HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION)
{
    //The association is missing
}

There's one other trick there, that took me some time to figure out -- DO NOT use AssocQueryStringA(). The shim for AssocQueryStringA() that converts its passed string parameters to Unicode has a bug in XP (and evidently in Vista as well) that will make that API fail on those OS. So, if you do your own ANSI-to-Unicode conversion and call AssocQueryStringW() the problem will go away (Evidently 14 years is not enough time for Microsoft to fix that bug?).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!