ReactOS  0.4.15-dev-492-ga1108f6
ClassNode.cpp
Go to the documentation of this file.
1 /*
2 * PROJECT: ReactOS Device Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/devmgr/devmgmt/ClassNode.cpp
5 * PURPOSE: Class object for
6 * COPYRIGHT: Copyright 2015 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9 
10 #include "precomp.h"
11 #include "devmgmt.h"
12 #include "ClassNode.h"
13 
14 
16  _In_ LPGUID ClassGuid,
18  ) :
20 {
21  CopyMemory(&m_ClassGuid, ClassGuid, sizeof(GUID));
22 }
23 
24 
26 {
27 }
28 
29 
30 bool
32 {
34  DWORD Success;
35  HKEY hKey;
36 
37  // Open the registry key for this class
41  NULL,
42  0);
43  if (hKey != INVALID_HANDLE_VALUE)
44  {
45  // Lookup the class description (win7+)
46  Size = sizeof(m_DisplayName);
48  L"ClassDesc",
49  NULL,
50  &Type,
52  &Size);
53  if (Success == ERROR_SUCCESS)
54  {
55  if (Type != REG_SZ)
56  {
58  }
59  // Check if the string starts with an @
60  else if (m_DisplayName[0] == L'@')
61  {
62  // The description is located in a module resource
64  }
65  }
66  else if (Success == ERROR_FILE_NOT_FOUND)
67  {
68  // WinXP stores the description in the default value
69  Size = sizeof(m_DisplayName);
71  NULL,
72  NULL,
73  &Type,
75  &Size);
76  if (Success == ERROR_SUCCESS && Type != REG_SZ)
77  {
79  }
80  }
81 
82  // Close the registry key
83  RegCloseKey(hKey);
84  }
85  else
86  {
88  }
89 
90  // Check if we failed to get the class description
91  if (Success != ERROR_SUCCESS)
92  {
93  // Use the class name as the description
98  &RequiredSize);
99  }
100 
101  // Get the image index for this class
103  &m_ClassGuid,
104  &m_ClassImage);
105 
106  return true;
107 }
108 
109 
110 DWORD
112  _Inout_z_ LPWSTR ResourceDescriptor,
113  _In_ DWORD ResourceDescriptorSize
114  )
115 {
116  WCHAR ModulePath[MAX_PATH];
117  WCHAR ResString[256];
118  INT ResourceId;
120  LPWSTR ptr;
121  DWORD Size;
122  DWORD dwError;
123 
124  // First check for a semi colon */
125  ptr = wcschr(ResourceDescriptor, L';');
126  if (ptr)
127  {
128  // This must be an inf based descriptor, the desc is after the semi colon
129  StringCbCopyW(ResourceDescriptor, ResourceDescriptorSize, ++ptr);
130  dwError = ERROR_SUCCESS;
131  }
132  else
133  {
134  // This must be a dll resource based descriptor. Find the comma
135  ptr = wcschr(ResourceDescriptor, L',');
136  if (ptr == NULL)
137  return ERROR_INVALID_DATA;
138 
139  // Terminate the string where the comma was
140  *ptr = UNICODE_NULL;
141 
142  // Expand any environment strings
143  Size = ExpandEnvironmentStringsW(&ResourceDescriptor[1], ModulePath, MAX_PATH);
144  if (Size > MAX_PATH)
145  return ERROR_BUFFER_OVERFLOW;
146  if (Size == 0)
147  return GetLastError();
148 
149  // Put the comma back and move past it
150  *ptr = L',';
151  ptr++;
152 
153  // Load the dll
155  if (hModule == NULL)
156  return GetLastError();
157 
158  // Convert the resource id to a number
159  ResourceId = _wtoi(ptr);
160 
161  // If the number is negative, make it positive
162  if (ResourceId < 0)
163  ResourceId = -ResourceId;
164 
165  // Load the string from the dll
166  if (LoadStringW(hModule, ResourceId, ResString, 256))
167  {
168  StringCbCopyW(ResourceDescriptor, ResourceDescriptorSize, ResString);
169  dwError = ERROR_SUCCESS;
170  }
171  else
172  {
173  dwError = GetLastError();
174  }
175 
176  // Free the library
178  }
179 
180  return dwError;
181 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
virtual bool SetupNode()
Definition: ClassNode.cpp:31
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI SetupDiClassNameFromGuidW(const GUID *ClassGuid, PWSTR ClassName, DWORD ClassNameSize, PDWORD RequiredSize)
Definition: devinst.c:1076
CClassNode(_In_ LPGUID ClassGuid, _In_ PSP_CLASSIMAGELIST_DATA ImageListData)
Definition: ClassNode.cpp:15
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:57
#define _Inout_z_
Definition: no_sal2.h:298
INT m_ClassImage
Definition: Node.h:20
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define UNICODE_NULL
static PVOID ptr
Definition: dispmode.c:27
#define DIOCR_INSTALLER
Definition: setupapi.h:176
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
Definition: Node.h:12
Definition: Node.h:8
#define FreeLibrary(x)
Definition: compat.h:414
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:26
#define CopyMemory
Definition: winbase.h:1646
GUID m_ClassGuid
Definition: Node.h:19
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI SetupDiGetClassImageIndex(IN PSP_CLASSIMAGELIST_DATA ClassImageListData, IN CONST GUID *ClassGuid, OUT PINT ImageIndex)
Definition: devclass.c:396
DWORD ConvertResourceDescriptorToString(_Inout_z_ LPWSTR ResourceDescriptor, _In_ DWORD ResourceDescriptorSize)
Definition: ClassNode.cpp:111
static const WCHAR L[]
Definition: oid.c:1250
#define VOID
Definition: acefi.h:82
PSP_CLASSIMAGELIST_DATA m_ImageListData
Definition: Node.h:16
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define ERROR_INVALID_DATA
Definition: winerror.h:116
#define _In_
Definition: no_sal2.h:204
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:338
WCHAR m_DisplayName[DISPLAY_NAME_LEN]
Definition: Node.h:18
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
HKEY WINAPI SetupDiOpenClassRegKeyExW(const GUID *ClassGuid, REGSAM samDesired, DWORD Flags, PCWSTR MachineName, PVOID Reserved)
Definition: devinst.c:3667
convenient loading of string resources
Definition: globals.h:303
WCHAR * LPWSTR
Definition: xmlstorage.h:184
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
SP_CLASSIMAGELIST_DATA ImageListData
Definition: hdwwiz.c:34
HMODULE hModule
Definition: animate.c:44
#define REG_SZ
Definition: layer.c:22