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 "DeviceNode.h"
15 CDeviceNode::CDeviceNode(
16 _In_opt_ DEVINST Device
,
17 _In_ PSP_CLASSIMAGELIST_DATA ImageListData
27 CDeviceNode::~CDeviceNode()
32 CDeviceNode::SetupNode()
34 WCHAR ClassGuidString
[MAX_GUID_STRING_LEN
];
38 // ATLASSERT(m_DeviceId == NULL);
40 // Get the length of the device id string
41 cr
= CM_Get_Device_ID_Size(&ulLength
, m_DevInst
, 0);
44 // We alloc heap here because this will be stored in the lParam of the TV
45 m_DeviceId
= (LPWSTR
)HeapAlloc(GetProcessHeap(),
47 (ulLength
+ 1) * sizeof(WCHAR
));
50 // Now get the actual device id
51 cr
= CM_Get_Device_IDW(m_DevInst
,
57 HeapFree(GetProcessHeap(), 0, m_DeviceId
);
63 // Make sure we got the string
64 if (m_DeviceId
== NULL
)
67 // Get the current status of the device
68 cr
= CM_Get_DevNode_Status_Ex(&m_Status
,
75 HeapFree(GetProcessHeap(), 0, m_DeviceId
);
80 // Check if the device has a problem
81 if (m_Status
& DN_HAS_PROBLEM
)
86 // The disabled overlay takes precidence over the problem overlay
87 if (m_ProblemNumber
& (CM_PROB_DISABLED
| CM_PROB_HARDWARE_DISABLED
))
93 // Get the class guid for this device
94 ulLength
= MAX_GUID_STRING_LEN
* sizeof(WCHAR
);
95 cr
= CM_Get_DevNode_Registry_PropertyW(m_DevInst
,
101 if (cr
== CR_SUCCESS
)
103 // Convert the string to a proper guid
104 CLSIDFromString(ClassGuidString
, &m_ClassGuid
);
108 // It's a device with no driver
109 m_ClassGuid
= GUID_DEVCLASS_UNKNOWN
;
113 // Get the image for the class this device is in
114 SetupDiGetClassImageIndex(m_ImageListData
,
118 // Get the description for the device
119 ulLength
= DISPLAY_NAME_LEN
* sizeof(WCHAR
);
120 cr
= CM_Get_DevNode_Registry_PropertyW(m_DevInst
,
126 if (cr
!= CR_SUCCESS
)
128 ulLength
= DISPLAY_NAME_LEN
* sizeof(WCHAR
);
129 cr
= CM_Get_DevNode_Registry_PropertyW(m_DevInst
,
138 // Cleanup if something failed
139 if (cr
!= CR_SUCCESS
)
141 HeapFree(GetProcessHeap(), 0, m_DeviceId
);
145 return (cr
== CR_SUCCESS
? true : false);
150 CDeviceNode::IsHidden()
153 cr
= CM_Get_DevNode_Status_Ex(&m_Status
,
158 if (cr
== CR_SUCCESS
)
160 return ((m_Status
& DN_NO_SHOW_IN_DM
) != 0);
167 CDeviceNode::CanDisable()
170 cr
= CM_Get_DevNode_Status_Ex(&m_Status
,
175 if (cr
== CR_SUCCESS
)
177 return ((m_Status
& DN_DISABLEABLE
) != 0);
184 CDeviceNode::IsDisabled()
187 cr
= CM_Get_DevNode_Status_Ex(&m_Status
,
192 if (cr
== CR_SUCCESS
)
194 return ((m_ProblemNumber
& (CM_PROB_DISABLED
| CM_PROB_HARDWARE_DISABLED
)) != 0);
201 CDeviceNode::IsStarted()
204 cr
= CM_Get_DevNode_Status_Ex(&m_Status
,
209 if (cr
== CR_SUCCESS
)
211 return ((m_Status
& DN_STARTED
) != 0);
218 CDeviceNode::IsInstalled()
221 cr
= CM_Get_DevNode_Status_Ex(&m_Status
,
226 if (cr
== CR_SUCCESS
)
228 return ((m_Status
& DN_HAS_PROBLEM
) != 0 ||
229 (m_Status
& (DN_DRIVER_LOADED
| DN_STARTED
)) != 0);