ReactOS 0.4.15-dev-7788-g1ad9096
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
30bool
32{
35 HKEY hKey;
36
37 // Open the registry key for this class
41 NULL,
42 0);
44 {
45 // Lookup the class description (win7+)
46 Size = sizeof(m_DisplayName);
48 L"ClassDesc",
49 NULL,
50 &Type,
52 &Size);
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
84 }
85 else
86 {
88 }
89
90 // Check if we failed to get the class description
92 {
93 // Use the class name as the description
99 }
100
101 // Get the image index for this class
104 &m_ClassImage);
105
106 return true;
107}
108
109
110DWORD
112 _Inout_z_ LPWSTR ResourceDescriptor,
113 _In_ DWORD ResourceDescriptorSize
114 )
115{
116 WCHAR ModulePath[MAX_PATH];
117 WCHAR ResString[256];
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)
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
160
161 // If the number is negative, make it positive
162 if (ResourceId < 0)
164
165 // Load the string from the dll
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}
@ ClassNode
Definition: Node.h:8
INT ResourceId
Type
Definition: Type.h:7
#define VOID
Definition: acefi.h:82
#define RegCloseKey(hKey)
Definition: registry.h:49
CClassNode(_In_ LPGUID ClassGuid, _In_ PSP_CLASSIMAGELIST_DATA ImageListData)
Definition: ClassNode.cpp:15
virtual bool SetupNode()
Definition: ClassNode.cpp:31
DWORD ConvertResourceDescriptorToString(_Inout_z_ LPWSTR ResourceDescriptor, _In_ DWORD ResourceDescriptorSize)
Definition: ClassNode.cpp:111
Definition: Node.h:13
INT m_ClassImage
Definition: Node.h:20
PSP_CLASSIMAGELIST_DATA m_ImageListData
Definition: Node.h:16
GUID m_ClassGuid
Definition: Node.h:19
WCHAR m_DisplayName[DISPLAY_NAME_LEN]
Definition: Node.h:18
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4132
HMODULE hModule
Definition: animate.c:44
#define wcschr
Definition: compat.h:17
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
BOOL WINAPI SetupDiGetClassImageIndex(IN PSP_CLASSIMAGELIST_DATA ClassImageListData, IN CONST GUID *ClassGuid, OUT PINT ImageIndex)
Definition: devclass.c:277
BOOL WINAPI SetupDiClassNameFromGuidW(const GUID *ClassGuid, PWSTR ClassName, DWORD ClassNameSize, PDWORD RequiredSize)
Definition: devinst.c:1067
HKEY WINAPI SetupDiOpenClassRegKeyExW(const GUID *ClassGuid, REGSAM samDesired, DWORD Flags, PCWSTR MachineName, PVOID Reserved)
Definition: devinst.c:3662
@ Success
Definition: eventcreate.c:712
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
SP_CLASSIMAGELIST_DATA ImageListData
Definition: hdwwiz.c:34
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static PVOID ptr
Definition: dispmode.c:27
#define _In_
Definition: ms_sal.h:308
#define _Inout_z_
Definition: ms_sal.h:383
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define DIOCR_INSTALLER
Definition: setupapi.h:176
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
convenient loading of string resources
Definition: globals.h:304
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
Definition: wdfdevice.h:4439
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
#define CopyMemory
Definition: winbase.h:1710
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define ERROR_INVALID_DATA
Definition: winerror.h:116
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184