AssocGetPerceivedType

Declaration

HRESULT
AssocGetPerceivedType (
    LPCWSTR pszExt, 
    PERCEIVED *ptype, 
    PERCEIVEDFLAG *pflag, 
    LPWSTR *ppszType);

Parameters

The pszExt argument provides the address of a case-insensitive null-terminated string that describes the type to look up.

The ptype argument provides the address of a variable that is to receive a code that identifies the perceived type.

The pflag argument provides the address of a variable that is to receive flags that describe the perceived type.

The ppszType argument provides the address of a variable that is to receive a string representation of the perceived type. The ppszType argument may be NULL if this information is not wanted.

Return Value

The function returns zero for success, else an error code.

The variables at ptype and pflag are meaningful even on failure.

Behaviour

If the given type is any of many file extensions for which information is hard-coded into SHLWAPI, then the function’s behaviour is determined entirely from the hard-coded information. The following large table shows the complete behaviour. Note that although the function recognises “.lnk” and “.search-ms” and produces data for the ptype and pflag arguments, there is no name for the perceived type and the function fails (returning E_FAIL).

Input Type Perceived Type Perceived Flag Name of Perceived Type
.aif PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.aifc PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.aiff PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.asf PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.asx PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.au PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.avi PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.bas PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.bat PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.bmp PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.cmd PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.com PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.cpl PERCEIVED_TYPE_SYSTEM PERCEIVEDFLAG_HARDCODED system
.dib PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.dvr-ms PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.emf PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.exe PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.gif PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.hta PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.htm PERCEIVED_TYPE_DOCUMENT PERCEIVEDFLAG_HARDCODED document
.html PERCEIVED_TYPE_DOCUMENT PERCEIVEDFLAG_HARDCODED document
.ico PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.IVF PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.jfif PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.jpe PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.jpeg PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.jpg PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.lnk PERCEIVED_TYPE_UNSPECIFIED PERCEIVEDFLAG_HARDCODED  
.m1v PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.m3u PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.mht PERCEIVED_TYPE_DOCUMENT PERCEIVEDFLAG_HARDCODED document
.mid PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.midi PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.msi PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.mp2 PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.mp2v PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.mp3 PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.mpa PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.mpe PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.mpeg PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.mpg PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.mpv2 PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.pif PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.png PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.reg PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.rle PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.rmi PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.scr PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.search-ms PERCEIVED_TYPE_UNSPECIFIED PERCEIVEDFLAG_HARDCODED  
.snd PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.tif PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.tiff PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.vb PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_HARDCODED application
.wav PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.wax PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.wm PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.wma PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
audio
.wmf PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_GDIPLUS
image
.wmv PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.wmx PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.wvx PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_WMSDK
video
.zip PERCEIVED_TYPE_COMPRESSED PERCEIVEDFLAG_HARDCODED
PERCEIVEDFLAG_NATIVESUPPORT
PERCEIVEDFLAG_ZIPFOLDER
compressed

Registration

If the given type is not a recognised file extension, the function looks for the perceived type in either of two registry keys, shown below in order of decreasing precedence:

Key: HKEY_CLASSES_ROOT\ext
HKEY_CLASSES_ROOT\SystemFileAssociations\ext
Value: PerceivedType
Type: REG_SZ or REG_EXPAND_SZ

where ext is the given type (and need not be a file extension). If the function falls back to the second key but cannot fit the longer registry path into MAX_PATH characters, it fails. If the function cannot read the value from either key (with a limit of 40 characters), it fails. In these cases of failure, the perceived type and flags returned through the ptype and pflag arguments are PERCEIVED_TYPE_FOLDER and PERCEIVEDFLAG_UNDEFINED respectively.

The string data for the PerceivedType value is the case-insensitive name of the perceived type. Each perceived type has hard-coded values for the descriptions that are returned through the ptype and pflag arguments: 

Name of Perceived Type Perceived Type Perceived Flag
none PERCEIVED_TYPE_UNSPECIFIED PERCEIVEDFLAG_SOFTCODED
application PERCEIVED_TYPE_APPLICATION PERCEIVEDFLAG_SOFTCODED
audio PERCEIVED_TYPE_AUDIO PERCEIVEDFLAG_SOFTCODED
compressed PERCEIVED_TYPE_COMPRESSED PERCEIVEDFLAG_SOFTCODED
document PERCEIVED_TYPE_DOCUMENT PERCEIVEDFLAG_SOFTCODED
gamemedia PERCEIVED_TYPE_GAMEMEDIA PERCEIVEDFLAG_SOFTCODED
PERCEIVEDFLAG_NATIVESUPPORT
image PERCEIVED_TYPE_IMAGE PERCEIVEDFLAG_SOFTCODED
system PERCEIVED_TYPE_SYSTEM PERCEIVEDFLAG_SOFTCODED
text PERCEIVED_TYPE_TEXT PERCEIVEDFLAG_SOFTCODED
PERCEIVEDFLAG_NATIVESUPPORT
video PERCEIVED_TYPE_VIDEO PERCEIVEDFLAG_SOFTCODED
else PERCEIVED_TYPE_CUSTOM PERCEIVEDFLAG_SOFTCODED

If the name from the registry value is recognised, then the name returned through the ppszType argument is the hard-coded name from the table. Otherwise, it is the name from the registry.

Returned Name

If the function cannot duplicate the name in order to return a pointer at the address given by ppszType, it fails. Memory for the name is found by the SHStrDup function and should be freed using CoTaskMemFree when the name is no longer needed.

Comment

Note that although Microsoft defines a PERCEIVED_TYPE_UNKNOWN and (more significantly) a PERCEIVED_TYPE_CONTACTS, it is not currently possible for this function to produce either of these values, and PERCEIVED_TYPE_FOLDER is nothing but the function’s default for an error. Conversely, Microsoft’s documentation has it that PERCEIVED_TYPE_DOCUMENT is “not used”, though plainly it is.

That the large table of hard-coded perceived types for recognised file extensions seems not yet to have been published anywhere (except in the SHLWAPI binary code) seems a little odd. It may be the closest that Microsoft comes to a list of so-called public file types. Surely though ought be listed somewhere, if only so that nobody will even think to try setting a perceived type for them in the registry.

Availability

The AssocGetPerceivedType function is exported by name from SHLWAPI.DLL in builds of version 6.00 from Windows XP SP2 and higher, from Windows Server 2003 SP1 and higher, and from Windows Vista and higher, and presumably in higher versions.