Using AssocQueryString to get 64-bit application command from 32-bit application, but not working

1

I try to use AssocQueryString to get association information, myapp.exe is 32-bit executable file. Here's my code.

WCHAR commandline[_MAX_PATH];
DWORD size = _MAX_PATH;
HRESULT h = AssocQueryStringW(ASSOCF_OPEN_BYEXENAME, ASSOCSTR_COMMAND, execName, 0, commandline, &size);
if (SUCCEEDED(h)) 
{ 
    ... 
}

I find that if "execName" is a 32-bit application, this api works perfect. For example,

WCHAR *execName = L"mspaint.exe";

We can get command = "C:\Windows\system32\mspaint.exe" "%1"

But if giving a 64-bit application(ex: PaintDotNet.exe), SUCCEEDED(h) would return FALSE. Variable h = 0x80070483, which means "no application is associated with the file extension".

Since above observation, I guess this api may fail when trying to get 64-bit application information.

So my question are:

  1. Is there anything I ignore or wrong usage of AssocQueryString?

  2. Is there another way to get a 64-bit app info from a 32-bit app?

By the way, I don't want to just compile my app as a 64-bit app.

Thank you for all your help.

c++
windows
winapi
visual-c++
32bit-64bit
asked on Stack Overflow Sep 8, 2013 by Mike Hung

1 Answer

0

1. Is there anything I ignore or wrong usage of AssocQueryString?

1) ASSOCSTR_COMMAND replace to ASSOCSTR_EXECUTABLE

and you can get just "C:\Windows\system32\mspaint.exe"

2) SUCCEEDED is non-negative numbers indicate true

(((HRESULT)(hr)) >= 0)

so if you check success, check result equal zero

2. Is there another way to get a 64-bit app info from a 32-bit app?

1) if your windows x64, folder C:\Windows\system32\ is for 64bit files.

cf>http://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm C:\Windows\System32 Windows System folder (system directory) for 64-bit files C:\Windows\SysWOW64 Windows System folder (system directory) for 32-bit files

2) just check result equal zero, and print it. do not use SUCCEEDED(h) in this case.

AssocQueryString's return value S_OK(0), E_POINTER, S_FALSE(1)

answered on Stack Overflow Mar 15, 2016 by bemaru

User contributions licensed under CC BY-SA 3.0