Microsoft KB Archive/316931

= BUG: &quot;Error LNK2001&quot; Error Message When You Call SHGetImageList on a Windows XP-Based System =

Article ID: 316931

Article Last Modified on 7/11/2005

-

APPLIES TO


 * Microsoft Platform Software Development Kit-January 2000 Edition

-



This article was previously published under Q316931



SYMPTOMS
When you call the SHGetImageList function on a Microsoft Windows XP-based system, you may receive the following error message:

MyFileName.obj : error LNK2001: unresolved external symbol _SHGetImageList

Debug/ MyFileName.exe : fatal error LNK1120: 1 unresolved externals

Error executing link.exe.



CAUSE
The SHGetImageList function is supported in Windows XP, as documented in the Platform SDK. However, because this function is not exported by name in the Shell32.dll file, it is not included in the Shell32.lib import library that is included with the Platform SDK.



RESOLUTION
To resolve this issue, use the LoadLibrary and GetProcAddress functions to call the SHGetImageList function by ordinal. The SHGetImageList ordinal is 727. For this particular case, the ordinal can be counted on to not change across operating system versions, but do not assume this to be true for any other application programming interface (API) unless specifically noted.

The following code demonstrates how to call SHGetImageList by ordinal: typedef HRESULT (STDMETHODCALLTYPE *SHGETIMAGELIST)(int, REFIID, void **);

STDAPI CallSHGetImageList(int iImageList,                          REFIID riid,                           void **ppv) {  HINSTANCE hinstShell32 = NULL; SHGETIMAGELIST pfn = NULL; HRESULT hr = S_OK; LPTSTR lpszLibPath = NULL; TCHAR tchBuffer[MAX_PATH*2]; lpszLibPath = tchBuffer;

GetSystemDirectory(lpszLibPath, MAX_PATH+1); strcat(lpszLibPath, _T(&quot;\\SHELL32.DLL&quot;));

hinstShell32 = LoadLibrary(lpszLibPath);

if (NULL == hinstShell32) {        DWORD err = GetLastError; return HRESULT_FROM_WIN32(err); }

//   // First, try to call the function by name. //   pfn = (SHGETIMAGELIST)GetProcAddress(hinstShell32,                                         (LPCSTR)&quot;SHGetImageList&quot;); if (NULL == pfn) {     //ONLY if the preceding call fails, try to call the function by ordinal pfn = (SHGETIMAGELIST)GetProcAddress(hinstShell32,                                          (LPCSTR)727); if (NULL == pfn) {        hr = HRESULT_FROM_WIN32(GetLastError); }  }

if (NULL != pfn) {     //       // Call the function. //      hr = (pfn)(iImageList, riid, ppv); }

FreeLibrary(hinstShell32); return hr; }



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Keywords: kberrmsg kbbug kbpending KB316931

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.