zeroc8
zeroc8

Reputation: 873

Shell32 GetDetailsOf Localization issue

Is there a reliable way to identify the filetype of a file across Windows platforms?

I've inherited a program which queries filetypes using the Shell32 GetDetailsOf function, which returns localized strings and causes an error if a non-english system is used (for example, on a german system GetDetailsOf(item,9) returns "Bild" instead of "Image").

Upvotes: 0

Views: 303

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37192

Using the textual description of a filetype is not a reliable way of identifying particular types of file. As you've noticed the description strings change from language to language, but they can also change within the one language depending on the software the user has installed (as a made up example, a .jpg file might have the description "JPEG image" on one system, and "Adobe Photoshop Image" on another system if the user has installed software that claims the filetypes and changes the description).

Instead, your best way of identifying the filetype is to look at the file's extension (.jpg in our example). What you do with it then is up to you and depends on your application. You might just have a hard-coded list of extensions that you work with, or to be more generic you could look in the registry for the filetype's "perceived type":

HKEY_CLASSES_ROOT\.jpg\PerceivedType

To see if that value is set to "image", "audio", etc.

Upvotes: 2

Related Questions