IExtractIconA::GetIconLocation method (shlobj_core.h)

Gets the location and index of an icon.


HRESULT GetIconLocation(
        UINT uFlags,
  [out] PSTR pszIconFile,
        UINT cchMax,
  [out] int  *piIndex,
  [out] UINT *pwFlags



Type: UINT

One or more of the following values. This parameter can also be NULL.

GIL_ASYNC (0x0020)

Set this flag to determine whether the icon should be extracted asynchronously. If the icon can be extracted rapidly, this flag is usually ignored. If extraction will take more time, GetIconLocation should return E_PENDING. See the Remarks for further discussion.


Retrieve information about the fallback icon. Fallback icons are usually used while the desired icon is extracted and added to the cache.


The icon is displayed in a Shell folder.


The icon indicates a shortcut. However, the icon extractor should not apply the shortcut overlay; that will be done later. Shortcut icons are state-independent.


The icon is in the open state if both open-state and closed-state images are available. If this flag is not specified, the icon is in the normal or closed state. This flag is typically used for folder objects.


Explicitly return either GIL_SHIELD or GIL_FORCENOSHIELD in pwFlags. Do not block if GIL_ASYNC is set.

[out] pszIconFile


A pointer to a buffer that receives the icon location. The icon location is a null-terminated string that identifies the file that contains the icon.


Type: UINT

The size of the buffer, in characters, pointed to by pszIconFile.

[out] piIndex

Type: int*

A pointer to an int that receives the index of the icon in the file pointed to by pszIconFile.

[out] pwFlags

Type: UINT*

A pointer to a UINT value that receives zero or a combination of the following values.


The physical image bits for this icon are not cached by the calling application.


The location is not a file name/index pair. The values in pszIconFile and piIndex cannot be passed to ExtractIcon or ExtractIconEx.

When this flag is omitted, the value returned in pszIconFile is a fully-qualified path name to either a .ico file or to a file that can contain icons. Also, the value returned in piIndex is an index into that file that identifies which of its icons to use. Therefore, when the GIL_NOTFILENAME flag is omitted, these values can be passed to ExtractIcon or ExtractIconEx.


All objects of this class have the same icon. This flag is used internally by the Shell. Typical implementations of IExtractIcon do not require this flag because the flag implies that an icon handler is not required to resolve the icon on a per-object basis. The recommended method for implementing per-class icons is to register a DefaultIcon for the class.


Each object of this class has its own icon. This flag is used internally by the Shell to handle cases like Setup.exe, where objects with identical names can have different icons. Typical implementations of IExtractIcon do not require this flag.


The calling application should create a document icon using the specified icon.

GIL_SHIELD (0x0200)

Windows Vista only. The calling application must stamp the icon with the UAC shield.


Windows Vista only. The calling application must not stamp the icon with the UAC shield.

Return value


Returns S_OK if the function returned a valid location, or S_FALSE if the Shell should use a default icon. If the GIL_ASYNC flag is set in uFlags, the method can return E_PENDING to indicate that icon extraction will be time-consuming.


When a client sets the GIL_ASYNC flag in uFlags and receives E_PENDING as a return value, it typically creates a background thread to extract the icon. It calls GetIconLocation from that thread, without the GIL_ASYNC flag, to retrieve the icon location. It then calls IExtractIcon::Extract to extract the icon. Returning E_PENDING implies that the object is free threaded. In other words, it can safely be called concurrently by multiple threads.

The GIL_DEFAULTICON flag is usually set in the case where the desired icon is found, but that icon is not present in the icon cache. Icon extraction is a low priority background process, and as such may be delayed by other processes. The default icon will be displayed in place of the final icon during the time that it takes for that final icon to be extracted, added to the cache, and made available.


Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header shlobj_core.h
DLL Shell32.dll (version 4.0 or later)