ExtractAssociatedIconA function (shellapi.h)

Gets a handle to an icon stored as a resource in a file or an icon stored in a file's associated executable file.

Syntax

HICON ExtractAssociatedIconA(
  [in]      HINSTANCE hInst,
  [in, out] LPSTR     pszIconPath,
  [in, out] WORD      *piIcon
);

Parameters

[in] hInst

Type: HINSTANCE

A handle to the instance of the calling application.

[in, out] pszIconPath

Type: LPTSTR

Pointer to a string that, on entry, specifies the full path and file name of the file that contains the icon. The function extracts the icon handle from that file, or from an executable file associated with that file.

When this function returns, if the icon handle was obtained from an executable file (either an executable file pointed to by lpIconPath or an associated executable file) the function stores the full path and file name of that executable in the buffer pointed to by this parameter.

[in, out] piIcon

Type: LPWORD

Pointer to a WORD value that, on entry, specifies the index of the icon whose handle is to be obtained.

When the function returns, if the icon handle was obtained from an executable file (either an executable file pointed to by lpIconPath or an associated executable file), this value points to the icon's index in that file.

Return value

Type: HICON

If the function succeeds, the return value is an icon handle. If the icon is extracted from an associated executable file, the function stores the full path and file name of the executable file in the string pointed to by lpIconPath, and stores the icon's identifier in the WORD pointed to by lpiIcon.

If the function fails, the return value is NULL.

Remarks

When it is no longer needed, the caller is responsible for freeing the icon handle returned by ExtractAssociatedIcon by calling the DestroyIcon function.

The ExtractAssociatedIcon function first looks for the indexed icon in the file specified by lpIconPath. If the function cannot obtain the icon handle from that file, and the file has an associated executable file, it looks in that executable file for an icon. Associations with executable files are based on file name extensions and are stored in the per-user part of the registry.

Note

The shellapi.h header defines ExtractAssociatedIcon as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header shellapi.h
DLL Shell32.dll
API set ext-ms-win-shell-shell32-l1-2-1 (introduced in Windows 10, version 10.0.10240)

See also

ExtractAssociatedIconEx

ExtractIcon

ExtractIconEx