Rewrite SetupDiGetClassImageListExW and SetupDiGetClassImageIndex which were completly wrong

Add stub for SetupDiDestroyClassImageList
Now, you can see some icons in device manager

svn path=/trunk/; revision=24338
This commit is contained in:
Hervé Poussineau 2006-10-01 09:05:19 +00:00
parent ebafbecc80
commit 72a9a3af12
4 changed files with 114 additions and 49 deletions

View file

@ -669,6 +669,38 @@ cleanup:
return ret; return ret;
} }
/***********************************************************************
* SetupDiDestroyClassImageList(SETUPAPI.@)
*/
BOOL WINAPI
SetupDiDestroyClassImageList(
IN PSP_CLASSIMAGELIST_DATA ClassImageListData)
{
struct ClassImageList *list;
BOOL ret = FALSE;
TRACE("%p\n", ClassImageListData);
if (!ClassImageListData)
SetLastError(ERROR_INVALID_PARAMETER);
else if (ClassImageListData->cbSize != sizeof(SP_CLASSIMAGELIST_DATA))
SetLastError(ERROR_INVALID_USER_BUFFER);
else if ((list = (struct ClassImageList *)ClassImageListData->Reserved) == NULL)
SetLastError(ERROR_INVALID_USER_BUFFER);
else if (list->magic != SETUP_CLASS_IMAGE_LIST_MAGIC)
SetLastError(ERROR_INVALID_USER_BUFFER);
else
{
//DestroyIcon()
//ImageList_Destroy();
FIXME("Stub %p\n", ClassImageListData);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
}
TRACE("Returning %d\n", ret);
return ret;
}
/*********************************************************************** /***********************************************************************
* SetupDiGetClassDescriptionA (SETUPAPI.@) * SetupDiGetClassDescriptionA (SETUPAPI.@)
*/ */
@ -1302,28 +1334,21 @@ SetupDiGetClassImageIndex(
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
else else
{ {
HKEY hKey = INVALID_HANDLE_VALUE; DWORD i;
INT iconIndex;
/* Read Icon registry entry into Buffer */ for (i = 0; i < list->NumberOfGuids; i++)
hKey = SetupDiOpenClassRegKeyExW(ClassGuid, KEY_QUERY_VALUE, DIOCR_INTERFACE, list->MachineName, NULL);
if (hKey == INVALID_HANDLE_VALUE)
goto cleanup;
if (!SETUP_GetIconIndex(hKey, &iconIndex))
goto cleanup;
if (iconIndex >= 0)
{ {
SetLastError(ERROR_INVALID_INDEX); if (IsEqualIID(ClassGuid, &list->Guids[i]))
goto cleanup; break;
} }
*ImageIndex = -iconIndex; if (i == list->NumberOfGuids || list->IconIndexes[i] < 0)
ret = TRUE; SetLastError(ERROR_FILE_NOT_FOUND);
else
cleanup: {
if (hKey != INVALID_HANDLE_VALUE) *ImageIndex = list->IconIndexes[i];
RegCloseKey(hKey); ret = TRUE;
}
} }
TRACE("Returning %d\n", ret); TRACE("Returning %d\n", ret);
@ -1388,11 +1413,24 @@ SetupDiGetClassImageListExW(
else else
{ {
struct ClassImageList *list = NULL; struct ClassImageList *list = NULL;
DWORD RequiredSize;
HICON hIcon;
DWORD size; DWORD size;
INT i;
size = FIELD_OFFSET(struct ClassImageList, szData); /* Get list of all class GUIDs in given computer */
if (MachineName) ret = SetupDiBuildClassInfoListExW(
size += (strlenW(MachineName) + 3) * sizeof(WCHAR); 0,
NULL,
0,
&RequiredSize,
MachineName,
NULL);
if (!ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
goto cleanup;
size = sizeof(struct ClassImageList)
+ (sizeof(GUID) + sizeof(INT)) * RequiredSize;
list = HeapAlloc(GetProcessHeap(), 0, size); list = HeapAlloc(GetProcessHeap(), 0, size);
if (!list) if (!list)
{ {
@ -1400,23 +1438,60 @@ SetupDiGetClassImageListExW(
goto cleanup; goto cleanup;
} }
list->magic = SETUP_CLASS_IMAGE_LIST_MAGIC; list->magic = SETUP_CLASS_IMAGE_LIST_MAGIC;
if (MachineName) list->NumberOfGuids = RequiredSize;
list->Guids = (GUID*)(list + 1);
list->IconIndexes = (INT*)((ULONG_PTR)(list + 1) + sizeof(GUID) * RequiredSize);
ret = SetupDiBuildClassInfoListExW(
0,
list->Guids,
list->NumberOfGuids,
&RequiredSize,
MachineName,
NULL);
if (!ret)
goto cleanup;
else if (RequiredSize != list->NumberOfGuids)
{ {
list->szData[0] = list->szData[1] = '\\'; /* Hm. Class list changed since last call. Ignore
strcpyW(list->szData + 2, MachineName); * this case as it should be very rare */
list->MachineName = list->szData; SetLastError(ERROR_GEN_FAILURE);
} ret = FALSE;
else goto cleanup;
{
list->MachineName = NULL;
} }
/* Prepare a HIMAGELIST */
InitCommonControls();
ClassImageListData->ImageList = ImageList_Create(16, 16, ILC_COLOR, 100, 10);
if (!ClassImageListData->ImageList)
goto cleanup;
ClassImageListData->Reserved = (ULONG_PTR)list; ClassImageListData->Reserved = (ULONG_PTR)list;
/* Now, we "simply" need to load icons associated with all class guids,
* and put their index in the image list in the IconIndexes array */
for (i = 0; i < list->NumberOfGuids; i++)
{
ret = SetupDiLoadClassIcon(
&list->Guids[i],
&hIcon,
NULL);
if (ret)
list->IconIndexes[i] = ImageList_AddIcon(ClassImageListData->ImageList, hIcon);
else
list->IconIndexes[i] = -1; /* Special value to tell that icon is unavailable */
}
ret = TRUE; ret = TRUE;
cleanup: cleanup:
if (!ret) if (!ret)
MyFree(list); {
if (ClassImageListData->Reserved)
SetupDiDestroyClassImageList(ClassImageListData);
else if (list)
MyFree(list);
}
} }
TRACE("Returning %d\n", ret); TRACE("Returning %d\n", ret);

View file

@ -17,6 +17,7 @@
<library>uuid</library> <library>uuid</library>
<library>wine</library> <library>wine</library>
<library>ntdll</library> <library>ntdll</library>
<library>comctl32</library>
<library>kernel32</library> <library>kernel32</library>
<library>advapi32</library> <library>advapi32</library>
<library>user32</library> <library>user32</library>

View file

@ -201,13 +201,14 @@ struct ClassImageList
{ {
DWORD magic; /* SETUP_CLASS_IMAGE_LIST_MAGIC */ DWORD magic; /* SETUP_CLASS_IMAGE_LIST_MAGIC */
/* Contains the name of the remote computer ('\\COMPUTERNAME' for example), /* Number of GUIDs contained in Guids and IconIndexes arrays */
* or NULL if related to local machine. Points into szData field at the DWORD NumberOfGuids;
* end of the structure */ /* Array of GUIDs associated to icons of the image list. Its size
PCWSTR MachineName; * is NumberOfGuids and is pointing after the end this structure */
GUID* Guids;
/* Variable size array (contains data for MachineName) */ /* Array of corresponding icons index in the image list. Its size
WCHAR szData[ANYSIZE_ARRAY]; * is NumberOfGuids and is pointing after the end this structure */
INT* IconIndexes;
}; };
extern HINSTANCE hInstance; extern HINSTANCE hInstance;

View file

@ -155,18 +155,6 @@ BOOL WINAPI SetupOpenLog(BOOL Reserved)
return TRUE; return TRUE;
} }
/***********************************************************************
* SetupDiDestroyClassImageList(SETUPAPI.@)
*/
BOOL WINAPI SetupDiDestroyClassImageList(PSP_CLASSIMAGELIST_DATA ClassImageListData)
{
FIXME ("Stub %p\n", ClassImageListData);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return TRUE;
}
/*********************************************************************** /***********************************************************************
* SetupDiRegisterDeviceInfo(SETUPAPI.@) * SetupDiRegisterDeviceInfo(SETUPAPI.@)
*/ */