views:

103

answers:

1

I want to check if a particular file can be successfully "OPEN"ed via ShellExecute, so I'm attempting to use AssocQueryString to discover this.

Example:

DWORD size = 1024;
TCHAR buff[1024];  // fixed size as dirty hack for testing

int err = AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".mxf", NULL ,buff , &size);
openAction->Enabled  = ((err == S_OK) || (err == S_FALSE)) && (size > 0);

Now, this almost works. If there's a registered application, I get the string.

But, there's a catch: On Vista, even if there is no registered application, It returns that the app c:\Windows\System32\shell32.dll is associated, which is the thing that brings up the 100% useless "Windows cannot open this file: Use the Web service to find the correct program?" dialog.

Obviously I want to hide that peice of cr*p from end users, but simply comparing the returned string to a constant seems like an ugly, brute-force and fragile way of doing it.

Also, hacking the registry to totally disable this dialog isn't a great idea.

What's a better option?

+4  A: 

I always use FindExecutable() to get the registered application for a given document.

fhe
Thanks - works perfectly, and "fails" correctly if no application is registered. Kicking myself for not finding this one...
Roddy
Great, glad it solves your problem :-)
fhe