ReactOS 0.4.16-dev-1339-gd8bfa93
hwresource.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS devmgr.dll
3 * FILE: dll/win32/devmgr/hwresource.c
4 * PURPOSE: ReactOS Device Manager
5 * PROGRAMMER: Johannes Anderwald <johannes.anderwald@reactos.org>
6 * UPDATE HISTORY:
7 * 2005/11/24 Created
8 */
9
10#include "precomp.h"
11#include "restypes.h"
12#include "properties.h"
13
14#include "resource.h"
15
16
17typedef struct
18{
21
22
24
25
26#define CX_TYPECOLUMN_WIDTH 120
27
28static VOID
30 IN HWND hWndDevList)
31{
32 LVCOLUMN lvc;
33 RECT rcClient;
34 WCHAR szColName[255];
35 int iCol = 0;
36
37 /* set the list view style */
40
41 GetClientRect(hWndDevList,
42 &rcClient);
43
44 /* add the list view columns */
45 lvc.mask = LVCF_TEXT | LVCF_WIDTH;
46 lvc.fmt = LVCFMT_LEFT;
47 lvc.pszText = szColName;
48
51 szColName,
52 sizeof(szColName) / sizeof(szColName[0])))
53 {
54 lvc.cx = CX_TYPECOLUMN_WIDTH;
55 (void)ListView_InsertColumn(hWndDevList,
56 iCol++,
57 &lvc);
58 }
61 szColName,
62 sizeof(szColName) / sizeof(szColName[0])))
63 {
64 lvc.cx = rcClient.right - CX_TYPECOLUMN_WIDTH -
66
67 (void)ListView_InsertColumn(hWndDevList,
68 iCol++,
69 &lvc);
70 }
71}
72
73VOID
75 IN HWND hWndDevList,
76 IN INT ItemCount,
77 IN LPWSTR ResourceType,
78 IN LPWSTR ResourceDescription)
79{
80 INT iItem;
81 LVITEM li = {0};
82
83 li.mask = LVIF_STATE | LVIF_TEXT;
84 li.iItem = ItemCount;
85 li.pszText = ResourceType;
86 //li.iImage = ClassDevInfo->ImageIndex;
87 iItem = ListView_InsertItem(hWndDevList, &li);
88
89 if (iItem != -1)
90 {
91 li.mask = LVIF_TEXT;
92 li.iItem = iItem;
93 li.iSubItem = 1;
94 li.pszText = ResourceDescription;
95 (void)ListView_SetItem(hWndDevList, &li);
96 }
97}
98
99VOID
102 IN HWND hWndDevList)
103{
104 WCHAR szBuffer[100];
105 WCHAR szDetail[100];
107 ULONG ItemCount = 0, Index;
108
109 ResourceList = (PCM_RESOURCE_LIST)dap->pResourceList;
110
111 for (Index = 0; Index < ResourceList->List[0].PartialResourceList.Count; Index++)
112 {
113 PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[Index];
115 {
116 if (LoadString(hDllInstance, IDS_RESOURCE_INTERRUPT, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
117 {
118 wsprintf(szDetail, L"0x%08x (%d)", Descriptor->u.Interrupt.Level, Descriptor->u.Interrupt.Vector);
119 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
120 ItemCount++;
121 }
122 }
123 else if (Descriptor->Type == CmResourceTypePort)
124 {
125 if (LoadString(hDllInstance, IDS_RESOURCE_PORT, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
126 {
127 wsprintf(szDetail, L"%08lx - %08lx", Descriptor->u.Port.Start.LowPart, Descriptor->u.Port.Start.LowPart + Descriptor->u.Port.Length - 1);
128 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
129 ItemCount++;
130 }
131 }
132 else if (Descriptor->Type == CmResourceTypeMemory)
133 {
134 if (LoadString(hDllInstance, IDS_RESOURCE_MEMORY_RANGE, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
135 {
136 wsprintf(szDetail, L"%08I64x - %08I64x", Descriptor->u.Memory.Start.QuadPart, Descriptor->u.Memory.Start.QuadPart + Descriptor->u.Memory.Length - 1);
137 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
138 ItemCount++;
139 }
140 }
141 else if (Descriptor->Type == CmResourceTypeDma)
142 {
143 if (LoadString(hDllInstance, IDS_RESOURCE_DMA, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
144 {
145 wsprintf(szDetail, L"%08ld", Descriptor->u.Dma.Channel);
146 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
147 ItemCount++;
148 }
149 }
150 }
151}
152
153
154static VOID
157{
158 /* set the device image */
159 SendDlgItemMessage(hwndDlg,
162 (WPARAM)dap->hDevIcon,
163 0);
164
165 /* set the device name edit control text */
166 SetDlgItemText(hwndDlg,
168 dap->szDevName);
169}
170
174 IN UINT uMsg,
177{
179 HWND hWndDevList;
180 INT_PTR Ret = FALSE;
181
183
184 if (hpd != NULL || uMsg == WM_INITDIALOG)
185 {
186 switch (uMsg)
187 {
188 case WM_INITDIALOG:
189 {
190 /* init list */
191 hWndDevList = GetDlgItem(hwndDlg, IDC_DRIVERRESOURCES);
192 InitializeDevicesList(hWndDevList);
193
195 if (hpd != NULL)
196 {
197 SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR)hpd);
198
199 UpdateDriverResourceDlg(hwndDlg, hpd);
200 AddResourceItems(hpd, hWndDevList);
201 }
202
203 Ret = TRUE;
204 break;
205 }
206 }
207 }
208
209 return Ret;
210}
211
212static
215 LPWSTR pszDeviceID)
216{
217 PCM_RESOURCE_LIST pResourceList = NULL;
218 HKEY hKey = NULL;
219 DWORD dwError, dwSize;
220
221 CStringW keyName = L"SYSTEM\\CurrentControlSet\\Enum\\";
222 keyName += pszDeviceID;
223 keyName += L"\\Control";
224
225 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &hKey);
226 if (dwError != ERROR_SUCCESS)
227 {
228 /* failed to open device instance log conf dir */
229 return NULL;
230 }
231
232 dwSize = 0;
233 RegQueryValueExW(hKey, L"AllocConfig", NULL, NULL, NULL, &dwSize);
234 if (dwSize == 0)
235 goto done;
236
237 pResourceList = static_cast<PCM_RESOURCE_LIST>(HeapAlloc(GetProcessHeap(), 0, dwSize));
238 if (pResourceList == NULL)
239 goto done;
240
241 dwError = RegQueryValueExW(hKey, L"AllocConfig", NULL, NULL, (LPBYTE)pResourceList, &dwSize);
242 if (dwError != ERROR_SUCCESS)
243 {
244 HeapFree(GetProcessHeap(), 0, pResourceList);
245 pResourceList = NULL;
246 }
247
248done:
249 if (hKey != NULL)
251
252 return pResourceList;
253}
254
255static
258 LPWSTR pszDeviceID)
259{
260 PCM_RESOURCE_LIST pResourceList = NULL;
261 HKEY hKey = NULL;
262 DWORD dwError, dwSize;
263
264 CStringW keyName = L"SYSTEM\\CurrentControlSet\\Enum\\";
265 keyName += pszDeviceID;
266 keyName += L"\\LogConf";
267
268 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &hKey);
269 if (dwError != ERROR_SUCCESS)
270 {
271 /* failed to open device instance log conf dir */
272 return NULL;
273 }
274
275 dwSize = 0;
276 RegQueryValueExW(hKey, L"BootConfig", NULL, NULL, NULL, &dwSize);
277 if (dwSize == 0)
278 goto done;
279
280 pResourceList = static_cast<PCM_RESOURCE_LIST>(HeapAlloc(GetProcessHeap(), 0, dwSize));
281 if (pResourceList == NULL)
282 goto done;
283
284 dwError = RegQueryValueExW(hKey, L"BootConfig", NULL, NULL, (LPBYTE)pResourceList, &dwSize);
285 if (dwError != ERROR_SUCCESS)
286 {
287 HeapFree(GetProcessHeap(), 0, pResourceList);
288 pResourceList = NULL;
289 }
290
291done:
292 if (hKey != NULL)
294
295 return pResourceList;
296}
297
298PVOID
300 LPWSTR pszDeviceID)
301{
302 PCM_RESOURCE_LIST pResourceList = NULL;
303
304 pResourceList = GetAllocatedResourceList(pszDeviceID);
305 if (pResourceList == NULL)
306 pResourceList = GetBootResourceList(pszDeviceID);
307
308 return (PVOID)pResourceList;
309}
#define RegCloseKey(hKey)
Definition: registry.h:49
static HINSTANCE hDllInstance
Definition: clb.c:9
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define IDC_DEVNAME
Definition: resource.h:227
#define IDS_RESOURCE_INTERRUPT
Definition: resource.h:129
#define IDS_RESOURCE_MEMORY_RANGE
Definition: resource.h:128
#define IDS_RESOURCE_PORT
Definition: resource.h:131
#define IDC_DEVICON
Definition: resource.h:226
#define IDC_DRIVERRESOURCES
Definition: resource.h:256
#define IDS_SETTING_COLUMN
Definition: resource.h:127
#define IDS_RESOURCE_DMA
Definition: resource.h:130
#define IDS_RESOURCE_COLUMN
Definition: resource.h:126
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
INT_PTR CALLBACK ResourcesProcDriverDlgProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: hwresource.cpp:173
static VOID UpdateDriverResourceDlg(IN HWND hwndDlg, IN PDEVADVPROP_INFO dap)
Definition: hwresource.cpp:155
PVOID GetResourceList(LPWSTR pszDeviceID)
Definition: hwresource.cpp:299
#define CX_TYPECOLUMN_WIDTH
Definition: hwresource.cpp:26
static PCM_RESOURCE_LIST GetAllocatedResourceList(LPWSTR pszDeviceID)
Definition: hwresource.cpp:214
VOID InsertListItem(IN HWND hWndDevList, IN INT ItemCount, IN LPWSTR ResourceType, IN LPWSTR ResourceDescription)
Definition: hwresource.cpp:74
struct HARDWARE_RESOURCE_DATA * PHARDWARE_RESOURCE_DATA
static PCM_RESOURCE_LIST GetBootResourceList(LPWSTR pszDeviceID)
Definition: hwresource.cpp:257
VOID AddResourceItems(IN PDEVADVPROP_INFO dap, IN HWND hWndDevList)
Definition: hwresource.cpp:100
static VOID InitializeDevicesList(IN HWND hWndDevList)
Definition: hwresource.cpp:29
#define for
Definition: utility.h:88
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
unsigned int UINT
Definition: ndis.h:50
#define KEY_READ
Definition: nt_native.h:1023
struct _DEVADVPROP_INFO * PDEVADVPROP_INFO
#define LPPROPSHEETPAGE
Definition: prsht.h:390
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2413
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2641
#define LVIF_STATE
Definition: commctrl.h:2317
#define LVCF_WIDTH
Definition: commctrl.h:2592
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2739
#define ListView_SetExtendedListViewStyle(hwndLV, dw)
Definition: commctrl.h:2730
#define LVITEM
Definition: commctrl.h:2380
#define LVIF_TEXT
Definition: commctrl.h:2314
#define ListView_SetItem(hwnd, pitem)
Definition: commctrl.h:2406
#define LVCFMT_LEFT
Definition: commctrl.h:2603
#define LVCF_TEXT
Definition: commctrl.h:2593
#define LVCOLUMN
Definition: commctrl.h:2586
#define CmResourceTypeMemory
Definition: restypes.h:106
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
#define CmResourceTypeDma
Definition: restypes.h:107
#define CmResourceTypePort
Definition: restypes.h:104
#define CmResourceTypeInterrupt
Definition: restypes.h:105
LONG right
Definition: windef.h:308
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
int32_t INT_PTR
Definition: typedefs.h:64
uint32_t DWORD_PTR
Definition: typedefs.h:65
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define DWLP_USER
Definition: winuser.h:883
#define STM_SETICON
Definition: winuser.h:2111
#define SM_CXVSCROLL
Definition: winuser.h:972
#define WM_INITDIALOG
Definition: winuser.h:1758
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define wsprintf
Definition: winuser.h:5950
#define LoadString
Definition: winuser.h:5904
#define SendDlgItemMessage
Definition: winuser.h:5927
int WINAPI GetSystemMetrics(_In_ int)
#define SetDlgItemText
Definition: winuser.h:5934
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184