BUG: "Error LNK2001" Error Message When You Call SHGetImageList on a Windows XP-Based System (316931)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0
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("\\SHELL32.DLL"));
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)"SHGetImageList");
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;
}
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbbug kberrmsg kbpending KB316931 |
---|
|