Tech Support > Microsoft Windows > Development Resources > Description of type?
Description of type?
Posted by William Payne on April 21st, 2004


Hello, when you use Explorer to browse your hard disks and you are in
"detailed list mode", there is a Type column with a short description on
(known) file types. It might say "Movie file (mpgeg)" for an .mpg-file.
I was wondering what win32 api call is used to obtain that description? Or
do you look it up in the registry? If so, where? I would like to have this
functionality in program. I scanned my msdn docs but couldn't find anything.

/ WP


Posted by Damian Driscoll on April 21st, 2004


William Payne wrote:

You look it up in the registry. For example, for text files you would look
in HKEY_CLASSES_ROOT\.txt which has a default value of "txtfile". You would
then look at HKEY_CLASSES_ROOT\txtfile which has a default value of "Text
Document".

Here's an example of how to do it:

/*! \file FindType.c */

#include <stdio.h>
#include "windows.h"

int main(int argc,char **argv)
{
char Value[1024];
HKEY Key;
HKEY TypeKey;
DWORD Type,Size;

if(argc == 2)
{
if(RegOpenKeyEx(HKEY_CLASSES_ROOT,argv[1],0,KEY_READ,&Key) ==
ERROR_SUCCESS)
{
Size = sizeof(Value);
if(RegQueryValueEx(Key,NULL,NULL,&Type,Value,&Size ) == ERROR_SUCCESS)
{
if(RegOpenKeyEx(HKEY_CLASSES_ROOT,Value,0,KEY_READ ,&TypeKey) ==
ERROR_SUCCESS)
{
Size = sizeof(Value);
if(RegQueryValueEx(TypeKey,NULL,NULL,&Type,Value,& Size) ==
ERROR_SUCCESS)
printf("%s\r\n",Value);
RegCloseKey(TypeKey);
}
}
RegCloseKey(Key);
}
}
else
printf("Useage: Findtype .ext\r\nExample: Findtype .txt\r\n");

return 0;
}

Damian


Posted by Jugoslav Dujic on April 21st, 2004


Damian Driscoll wrote:
| William Payne wrote:
|
|| Hello, when you use Explorer to browse your hard disks and you are in
|| "detailed list mode", there is a Type column with a short description on
|| (known) file types. It might say "Movie file (mpgeg)" for an .mpg-file.
|| I was wondering what win32 api call is used to obtain that description? Or
|| do you look it up in the registry? If so, where? I would like to have this
|| functionality in program. I scanned my msdn docs but couldn't find
|| anything.
|
| You look it up in the registry. For example, for text files you would look
| in HKEY_CLASSES_ROOT\.txt which has a default value of "txtfile". You would
| then look at HKEY_CLASSES_ROOT\txtfile which has a default value of "Text
| Document".
|
| Here's an example of how to do it:
|
| /*! \file FindType.c */

....however, SHGetFileInfo->FILEINFO.szTypeName does it in a portable way.

--
Jugoslav
___________
www.geocities.com/jdujic

Please reply to the newsgroup.
You can find my real e-mail on my home page above.

Posted by Damian Driscoll on April 21st, 2004


Jugoslav Dujic wrote:
Sigh
so many ways to skin a cat!

The background behind my method was that I once needed to call
FindExecutable and found that it was unreliable for incorrectly installed
applications if the installation path had a space in it (the whole path
should have been enclosed in double quotes in the registry but wasn't and
FindExecutable just returned everything up to the first space rather than
the full path). Since the type description is stored under the same
registry key as the executable path I used the same method to get it.

It's also worth pointing out that the registry method does not require an
existing filename to work and will work on all versions of Windows from 95
to XP (may even work on 3.1 and earlier but can't remember and can't be
bothered checking!)

Damian

Posted by William Payne on April 21st, 2004



"Jugoslav Dujic" <jdujic@yahoo.com> wrote in message
news:c661uq$87en9$1@ID-106075.news.uni-berlin.de...
Thanks for your help, both of you. Before I noticed Jugoslav's approach I
had already implemented the registry variant, but I will most likely switch
to using SHGetFileInfo() instead.

Thanks again

/ WP



Posted by Raymond Chen on April 22nd, 2004


On Wed, 21 Apr 2004 16:54:43 +0200, "Jugoslav Dujic"
<jdujic@yahoo.com> wrote:
SHGetFileInfo also works on multilingual versions of Windows,
whereas the registry version works only on single-language
versions of Windows.


Similar Posts