2 * PROJECT: ReactOS Device Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/devmgr/devmgr/ClassNode.cpp
5 * PURPOSE: Class object for
6 * COPYRIGHT: Copyright 2015 Ged Murphy <gedmurphy@reactos.org>
12 #include "ClassNode.h"
15 CClassNode::CClassNode(
16 _In_ LPGUID ClassGuid
,
17 _In_ PSP_CLASSIMAGELIST_DATA ImageListData
21 CopyMemory(&m_ClassGuid
, ClassGuid
, sizeof(GUID
));
25 CClassNode::~CClassNode()
31 CClassNode::SetupNode()
33 DWORD RequiredSize
, Type
, Size
;
37 // Open the registry key for this class
38 hKey
= SetupDiOpenClassRegKeyExW(&m_ClassGuid
,
43 if (hKey
!= INVALID_HANDLE_VALUE
)
45 Size
= DISPLAY_NAME_LEN
;
48 // Lookup the class description (win7+)
49 Success
= RegQueryValueExW(hKey
,
53 (LPBYTE
)m_DisplayName
,
55 if (Success
== ERROR_SUCCESS
)
57 // Check if the string starts with an @
58 if (m_DisplayName
[0] == L
'@')
60 // The description is located in a module resource
61 Success
= ConvertResourceDescriptorToString(m_DisplayName
, DISPLAY_NAME_LEN
);
64 else if (Success
== ERROR_FILE_NOT_FOUND
)
66 // WinXP stores the description in the default value
67 Success
= RegQueryValueExW(hKey
,
71 (LPBYTE
)m_DisplayName
,
75 // Close the registry key
80 Success
= GetLastError();
83 // Check if we failed to get the class description
84 if (Success
!= ERROR_SUCCESS
)
86 // Use the class name as the description
87 RequiredSize
= DISPLAY_NAME_LEN
;
88 (VOID
)SetupDiClassNameFromGuidW(&m_ClassGuid
,
94 // Get the image index for this class
95 (VOID
)SetupDiGetClassImageIndex(m_ImageListData
,
104 CClassNode::ConvertResourceDescriptorToString(
105 _Inout_z_ LPWSTR ResourceDescriptor
,
106 _In_ DWORD ResourceDescriptorSize
109 WCHAR ModulePath
[MAX_PATH
];
110 WCHAR ResString
[256];
118 // First check for a semi colon */
119 ptr
= wcschr(ResourceDescriptor
, L
';');
122 // This must be an inf based descriptor, the desc is after the semi colon
123 wcscpy_s(ResourceDescriptor
, ResourceDescriptorSize
, ++ptr
);
124 dwError
= ERROR_SUCCESS
;
128 // This must be a dll resource based descriptor. Find the comma
129 ptr
= wcschr(ResourceDescriptor
, L
',');
130 if (ptr
== NULL
) return ERROR_INVALID_DATA
;
132 // Terminate the string where the comma was
135 // Expand any environment strings
136 Size
= ExpandEnvironmentStringsW(&ResourceDescriptor
[1], ModulePath
, MAX_PATH
);
137 if (Size
> MAX_PATH
) return ERROR_BUFFER_OVERFLOW
;
138 if (Size
== 0) return GetLastError();
140 // Put the comma back and move past it
145 hModule
= LoadLibraryExW(ModulePath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
146 if (hModule
== NULL
) return GetLastError();
148 // Convert the resource id to a number
149 ResourceId
= _wtoi(ptr
);
151 // If the number is negative, make it positive
152 if (ResourceId
< 0) ResourceId
= -ResourceId
;
154 // Load the string from the dll
155 if (LoadStringW(hModule
, ResourceId
, ResString
, 256))
157 wcscpy_s(ResourceDescriptor
, ResourceDescriptorSize
, ResString
);
158 dwError
= ERROR_SUCCESS
;
162 dwError
= GetLastError();
166 FreeLibrary(hModule
);