Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

904 lines
27 KiB

  1. /**------------------------------------------------------------------
  2. cmtest.c
  3. ------------------------------------------------------------------**/
  4. //
  5. // Includes
  6. //
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <wtypes.h>
  11. #include <cfgmgr32.h>
  12. #include <setupapi.h>
  13. #include "cmtest.h"
  14. #include "pnptest.h"
  15. #include <objbase.h>
  16. #include <initguid.h>
  17. #include <winioctl.h>
  18. #include <dbt.h>
  19. #include <pnpmgr.h>
  20. //
  21. // external prototypes
  22. //
  23. CONFIGRET
  24. CMP_Init_Detection(
  25. IN ULONG ulPrivateID
  26. );
  27. CONFIGRET
  28. CMP_Report_LogOn(
  29. IN ULONG ulPrivateID,
  30. IN ULONG ProccesID
  31. );
  32. VOID
  33. ConnectTest(
  34. HWND hWnd
  35. );
  36. VOID
  37. CallPnPIsaDetect(
  38. HWND hDlg,
  39. LPTSTR pszDevice
  40. );
  41. VOID
  42. DumpDeviceChangeData(
  43. HWND hWnd,
  44. WPARAM wParam,
  45. LPARAM lParam
  46. );
  47. //
  48. // Private Prototypes
  49. //
  50. //
  51. // Globals
  52. //
  53. HINSTANCE hInst;
  54. TCHAR szAppName[] = TEXT("CMTest");
  55. TCHAR szDebug[MAX_PATH];
  56. TCHAR szMachineName[MAX_PATH];
  57. HMACHINE hMachine = NULL;
  58. DEFINE_GUID(FunctionClassGuid1, 0xAAAAAAA1L, 0xE3F0, 0x101B, 0x84, 0x88, 0x00, 0xAA, 0x00, 0x3E, 0x56, 0x01);
  59. typedef BOOL (WINAPI *FP_DEVINSTALL)(HWND, LPCWSTR, BOOL, PDWORD);
  60. //
  61. // FROM NTOS\DD\WDM\DDK\INC\HIDCLASS.H
  62. //
  63. DEFINE_GUID( GUID_CLASS_INPUT, 0x4D1E55B2L, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, \
  64. 0x11, 0x11, 0x00, 0x00, 0x30);
  65. #define GUID_CLASS_INPUT_STR TEXT("4D1E55B2-F16F-11CF-88CB-001111000030")
  66. /**----------------------------------------------------------------------**/
  67. int APIENTRY
  68. WinMain(
  69. HINSTANCE hInstance,
  70. HINSTANCE hPrevInstance,
  71. LPSTR lpCmdLine,
  72. int nCmdShow
  73. )
  74. {
  75. MSG msg;
  76. if (!InitApplication(hInstance)) {
  77. return FALSE;
  78. }
  79. if (!InitInstance(hInstance, nCmdShow)) {
  80. return FALSE;
  81. }
  82. while (GetMessage(&msg, NULL, 0, 0)) {
  83. TranslateMessage(&msg);
  84. DispatchMessage(&msg);
  85. }
  86. return msg.wParam;
  87. } // WinMain
  88. /**----------------------------------------------------------------------**/
  89. BOOL
  90. InitApplication(
  91. HINSTANCE hInstance
  92. )
  93. {
  94. WNDCLASS wc;
  95. wc.style = CS_HREDRAW | CS_VREDRAW;
  96. wc.lpfnWndProc = MainWndProc;
  97. wc.cbClsExtra = 0;
  98. wc.cbWndExtra = 0;
  99. wc.hInstance = hInstance;
  100. wc.hIcon = LoadIcon (hInstance, szAppName);
  101. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  102. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  103. wc.lpszMenuName = szAppName;
  104. wc.lpszClassName = szAppName;
  105. return RegisterClass(&wc);
  106. } // InitApplication
  107. /**----------------------------------------------------------------------**/
  108. BOOL
  109. InitInstance(
  110. HINSTANCE hInstance,
  111. int nCmdShow
  112. )
  113. {
  114. HWND hWnd;
  115. WORD CMVersion;
  116. ULONG CMState = 0;
  117. TCHAR szTitle[MAX_PATH];
  118. hInst = hInstance;
  119. CMVersion = CM_Get_Version();
  120. if (CM_Get_Global_State(&CMState, 0) != CR_SUCCESS) {
  121. MessageBeep(0);
  122. }
  123. wsprintf(szTitle, TEXT("CM API Test Harness - CM State = %x, CM Version %d.%d"),
  124. CMState, HIBYTE(CMVersion), LOBYTE(CMVersion));
  125. hWnd = CreateWindow(
  126. szAppName,
  127. szTitle,
  128. WS_OVERLAPPEDWINDOW,
  129. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  130. NULL,
  131. NULL,
  132. hInstance,
  133. NULL);
  134. if (!hWnd) {
  135. return FALSE;
  136. }
  137. ShowWindow(hWnd, nCmdShow);
  138. UpdateWindow(hWnd);
  139. return TRUE;
  140. } // InitInstance
  141. /**----------------------------------------------------------------------**/
  142. LRESULT CALLBACK
  143. MainWndProc(
  144. HWND hWnd,
  145. UINT message,
  146. WPARAM wParam,
  147. LPARAM lParam
  148. )
  149. {
  150. HANDLE hTestFile = NULL;
  151. DWORD size = 0;
  152. ULONG status, ulType, i;
  153. HDEVNOTIFY hDevNotify;
  154. HDEVNOTIFY hNotify[64];
  155. HDEVNOTIFY hNotifyDevNode = NULL;
  156. HANDLE hFile[64];
  157. DEV_BROADCAST_DEVICEINTERFACE FilterData;
  158. DEV_BROADCAST_HANDLE HandleData;
  159. BOOL bStatus = TRUE;
  160. FP_DEVINSTALL fpDevInstall = NULL;
  161. HMODULE hModule = NULL;
  162. BOOL bReboot = FALSE;
  163. GUID InterfaceGuid;
  164. LPTSTR pBuffer, p;
  165. TCHAR szDeviceId[MAX_PATH];
  166. DEVNODE dnDevNode;
  167. LPBYTE buffer;
  168. static ULONG count = 0;
  169. switch (message) {
  170. case WM_CREATE:
  171. DialogBox(hInst, MAKEINTRESOURCE(CONNECT_DIALOG), hWnd,
  172. (DLGPROC)ConnectDlgProc);
  173. break;
  174. case WM_DEVICECHANGE:
  175. MessageBeep(0);
  176. DumpDeviceChangeData(hWnd, wParam, lParam);
  177. break;
  178. case WM_COMMAND:
  179. switch (LOWORD(wParam)) {
  180. case IDM_CONNECT_TEST:
  181. ConnectTest(hWnd);
  182. break;
  183. case IDM_DEVICE_LIST:
  184. DialogBox(hInst, MAKEINTRESOURCE(DEVLIST_DIALOG), hWnd,
  185. (DLGPROC)DeviceListDlgProc);
  186. break;
  187. case IDM_SERVICE_LIST:
  188. DialogBox(hInst, MAKEINTRESOURCE(SERVICE_DIALOG), hWnd,
  189. (DLGPROC)ServiceListDlgProc);
  190. break;
  191. case IDM_RELATIONS_LIST:
  192. DialogBox(hInst, MAKEINTRESOURCE(RELATIONS_DIALOG), hWnd,
  193. (DLGPROC)RelationsListDlgProc);
  194. break;
  195. case IDM_DEVICE_OPS:
  196. DialogBox(hInst, MAKEINTRESOURCE(DEVICE_DIALOG), hWnd,
  197. (DLGPROC)DeviceDlgProc);
  198. break;
  199. case IDM_DEVNODE_KEY:
  200. DialogBox(hInst, MAKEINTRESOURCE(DEVNODEKEY_DIALOG), hWnd,
  201. (DLGPROC)DevKeyDlgProc);
  202. break;
  203. case IDM_CLASS_LIST:
  204. DialogBox(hInst, MAKEINTRESOURCE(CLASS_DIALOG), hWnd,
  205. (DLGPROC)ClassDlgProc);
  206. break;
  207. case IDM_REGRESSION:
  208. DialogBox(hInst, MAKEINTRESOURCE(REGRESSION_DIALOG), hWnd,
  209. (DLGPROC)RegressionDlgProc);
  210. break;
  211. case IDM_EXIT:
  212. DestroyWindow(hWnd);
  213. break;
  214. case IDM_INIT_DETECTION:
  215. CMP_Init_Detection(0x07020420);
  216. break;
  217. case IDM_REPORTLOGON:
  218. CMP_Report_LogOn(0x07020420, GetCurrentProcessId());
  219. break;
  220. case IDM_PNPISA_DETECT:
  221. CallPnPIsaDetect(hWnd, TEXT("Root\\Device001\\0000"));
  222. break;
  223. case IDM_DEVINSTALL:
  224. hModule = LoadLibrary(TEXT("newdev.cpl"));
  225. if (hModule == NULL) {
  226. OutputDebugString(TEXT("LoadLibrary of newdev.cpl failed\n"));
  227. break;
  228. }
  229. if (!(fpDevInstall = (FP_DEVINSTALL)GetProcAddress(hModule, "InstallDevInst"))) {
  230. OutputDebugString(TEXT("GetProcAddress failed\n"));
  231. break;;
  232. }
  233. if (!(fpDevInstall)(NULL, L"PnPTest\\Pdo0\\Root&LEGACY_PNPTEST&0000&1111", FALSE, &bReboot)) {
  234. OutputDebugString(TEXT("InstallDevInst failed\n"));
  235. }
  236. FreeLibrary(hModule);
  237. break;
  238. //-----------------------------------------------------------
  239. // Notification
  240. //-----------------------------------------------------------
  241. case IDM_REGISTER_NOTIFY:
  242. //
  243. // Register for notification on pnptest interface devices
  244. //
  245. #if 0
  246. wsprintf(szDebug, TEXT("CMTEST: Registering window %d for pnptest interface notification\n"), hWnd);
  247. OutputDebugString(szDebug);
  248. FilterData.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
  249. FilterData.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
  250. FilterData.dbcc_reserved = 0;
  251. memcpy(&FilterData.dbcc_classguid, &FunctionClassGuid1, sizeof(GUID));
  252. FilterData.dbcc_name[0] = 0x0;
  253. hDevNotify = RegisterDeviceNotification(hWnd,
  254. &FilterData,
  255. DEVICE_NOTIFY_WINDOW_HANDLE);
  256. #endif
  257. //
  258. // Register for notification on HID target devices
  259. //
  260. wsprintf(szDebug, TEXT("CMTEST: Registering window %d for hid target notification\n"), hWnd);
  261. OutputDebugString(szDebug);
  262. count = 0;
  263. pBuffer = malloc(2048 * sizeof(TCHAR));
  264. CM_Get_Device_Interface_List((LPGUID)&GUID_CLASS_INPUT, NULL, pBuffer, 2048,
  265. CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
  266. for (p = pBuffer; *p; p += lstrlen(p) + 1) {
  267. hFile[count] = CreateFile(p, GENERIC_READ | GENERIC_WRITE,
  268. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
  269. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  270. if (hFile[count] != INVALID_HANDLE_VALUE) {
  271. wsprintf(szDebug, TEXT(" %s\n"), p);
  272. OutputDebugString(szDebug);
  273. HandleData.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
  274. HandleData.dbch_devicetype = DBT_DEVTYP_HANDLE;
  275. HandleData.dbch_reserved = 0;
  276. HandleData.dbch_handle = hFile[count];
  277. hNotify[count] = RegisterDeviceNotification(hWnd,
  278. &HandleData,
  279. DEVICE_NOTIFY_WINDOW_HANDLE);
  280. count++;
  281. } else {
  282. status = GetLastError();
  283. }
  284. }
  285. free(pBuffer);
  286. //
  287. // Register for notification on storage target devices
  288. //
  289. wsprintf(szDebug, TEXT("CMTEST: Registering window %d for storage target notification\n"), hWnd);
  290. OutputDebugString(szDebug);
  291. pBuffer = malloc(2048 * sizeof(TCHAR));
  292. CM_Get_Device_Interface_List((LPGUID)&VolumeClassGuid, NULL, pBuffer, 2048,
  293. CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
  294. for (p = pBuffer; *p; p += lstrlen(p) + 1) {
  295. hFile[count] = CreateFile(p, GENERIC_READ | GENERIC_WRITE,
  296. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
  297. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  298. if (hFile[count] != INVALID_HANDLE_VALUE) {
  299. wsprintf(szDebug, TEXT(" %s\n"), p);
  300. OutputDebugString(szDebug);
  301. HandleData.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
  302. HandleData.dbch_devicetype = DBT_DEVTYP_HANDLE;
  303. HandleData.dbch_reserved = 0;
  304. HandleData.dbch_handle = hFile[count];
  305. hNotify[count] = RegisterDeviceNotification(hWnd,
  306. &HandleData,
  307. DEVICE_NOTIFY_WINDOW_HANDLE);
  308. count++;
  309. } else {
  310. status = GetLastError();
  311. }
  312. }
  313. break;
  314. case IDM_UNREGISTER_NOTIFY:
  315. #if 0
  316. bStatus = UnregisterDeviceNotification(hDevNotify);
  317. #endif
  318. for (i = 0; i < count; i++) {
  319. if (hNotify[i]) {
  320. bStatus = UnregisterDeviceNotification(hNotify[i]);
  321. }
  322. if (hFile[i]) {
  323. CloseHandle(hFile[i]);
  324. }
  325. }
  326. break;
  327. case IDM_SET_ASSOCIATIONS:
  328. hTestFile = CreateFile(L"\\\\.\\PnPTest", GENERIC_READ | GENERIC_WRITE,
  329. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
  330. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  331. if (hTestFile == INVALID_HANDLE_VALUE) {
  332. status = GetLastError();
  333. }
  334. DeviceIoControl(hTestFile, (DWORD)IOCTL_SET, NULL, 0, NULL, 0, &size, NULL);
  335. CloseHandle(hTestFile);
  336. break;
  337. case IDM_CLEAR_ASSOCIATIONS:
  338. hTestFile = CreateFile(L"\\\\.\\PnPTest", GENERIC_READ | GENERIC_WRITE,
  339. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
  340. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  341. DeviceIoControl(hTestFile, (DWORD)IOCTL_CLEAR, NULL, 0, NULL, 0, &size, NULL);
  342. CloseHandle(hTestFile);
  343. break;
  344. case IDM_GET_PROPERTIES:
  345. lstrcpy(szDeviceId, TEXT("Root\\LEGACY_PNPTEST\\0000"));
  346. UuidFromString(TEXT("aaaaaaa2-e3f0-101b-8488-00aa003e5601"), &InterfaceGuid);
  347. pBuffer = malloc(1024);
  348. CM_Get_Device_Interface_List(&InterfaceGuid, szDeviceId, pBuffer, 512,
  349. CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
  350. // use first returned interface device of that class
  351. hTestFile = CreateFile(pBuffer, GENERIC_READ | GENERIC_WRITE,
  352. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
  353. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  354. if (hTestFile == INVALID_HANDLE_VALUE) {
  355. status = GetLastError();
  356. }
  357. DeviceIoControl(hTestFile, (DWORD)IOCTL_GET_PROP, NULL, 0, NULL, 0, &size, NULL);
  358. CloseHandle(hTestFile);
  359. CM_Locate_DevNode(&dnDevNode, TEXT("Root\\LEGACY_PNPTEST\\0000"), CM_LOCATE_DEVNODE_NORMAL);
  360. buffer = malloc(1024);
  361. size = 1024;
  362. status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_BUSTYPEGUID,
  363. &ulType, buffer, &size, 0);
  364. size = 1024;
  365. status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_LEGACYBUSTYPE,
  366. &ulType, buffer, &size, 0);
  367. size = 1024;
  368. status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_BUSNUMBER,
  369. &ulType, buffer, &size, 0);
  370. free(pBuffer);
  371. free(buffer);
  372. break;
  373. default:
  374. return DefWindowProc(hWnd, message, wParam, lParam);
  375. }
  376. break;
  377. case WM_DESTROY:
  378. if (hMachine != NULL) {
  379. CM_Disconnect_Machine(hMachine);
  380. }
  381. PostQuitMessage(0);
  382. break;
  383. default:
  384. return DefWindowProc(hWnd, message, wParam, lParam);
  385. }
  386. return 0;
  387. } // MainWndProc
  388. /**----------------------------------------------------------------------**/
  389. LRESULT CALLBACK
  390. ConnectDlgProc(
  391. HWND hDlg,
  392. UINT message,
  393. WPARAM wParam,
  394. LPARAM lParam
  395. )
  396. {
  397. CONFIGRET Status;
  398. WORD CMLocalVersion, CMRemoteVersion;
  399. ULONG CMState = 0;
  400. TCHAR szTitle[MAX_PATH];
  401. switch (message) {
  402. case WM_INITDIALOG:
  403. CheckRadioButton(hDlg, ID_RAD_LOCAL, ID_RAD_REMOTE, ID_RAD_LOCAL);
  404. return TRUE;
  405. case WM_COMMAND:
  406. switch(LOWORD(wParam)) {
  407. case ID_RAD_LOCAL:
  408. case ID_RAD_REMOTE:
  409. CheckRadioButton(hDlg, ID_RAD_LOCAL, ID_RAD_REMOTE, LOWORD(wParam));
  410. break;
  411. case IDOK:
  412. if (IsDlgButtonChecked(hDlg, ID_RAD_LOCAL)) {
  413. hMachine = NULL;
  414. }
  415. else {
  416. // a NULL machine name just returns local machine handle
  417. GetDlgItemText(hDlg, ID_ED_MACHINE, szMachineName, MAX_PATH);
  418. Status = CM_Connect_Machine(szMachineName, &hMachine);
  419. if (Status != CR_SUCCESS) {
  420. wsprintf(szDebug, TEXT("CM_Connect_Machine failed (%xh)"), Status);
  421. MessageBox(hDlg, szDebug, szAppName, MB_OK);
  422. hMachine = NULL;
  423. EndDialog(hDlg, FALSE);
  424. return TRUE;
  425. }
  426. CMLocalVersion = CM_Get_Version();
  427. CMRemoteVersion = CM_Get_Version_Ex(hMachine);
  428. Status = CM_Get_Global_State(&CMState, 0);
  429. if (Status != CR_SUCCESS) {
  430. MessageBeep(0);
  431. }
  432. wsprintf(szTitle,
  433. TEXT("CM API Test Harness - CM State = %x, CM Version Local %d.%d, Remote %d.%d"),
  434. CMState,
  435. HIBYTE(CMLocalVersion), LOBYTE(CMLocalVersion),
  436. HIBYTE(CMRemoteVersion), LOBYTE(CMRemoteVersion));
  437. SendMessage(GetParent(hDlg), WM_SETTEXT, 0, (LPARAM)(LPSTR)szTitle);
  438. }
  439. EndDialog(hDlg, TRUE);
  440. return TRUE;
  441. default:
  442. break;
  443. }
  444. }
  445. return FALSE;
  446. } // ConnectDlgProc
  447. VOID
  448. ConnectTest(
  449. HWND hWnd
  450. )
  451. {
  452. CONFIGRET Status = CR_SUCCESS;
  453. TCHAR szDeviceID[MAX_DEVICE_ID_LEN], szComputerName[MAX_PATH];
  454. ULONG ulSize = 0;
  455. DEVINST dnDevNode;
  456. HMACHINE hMachine;
  457. //---------------------------------------------------------------
  458. // 1. Text implicit local machine call
  459. //---------------------------------------------------------------
  460. szDeviceID[0] = 0x0;
  461. Status = CM_Locate_DevNode(&dnDevNode, TEXT("Root\\Device001\\0000"),
  462. CM_LOCATE_DEVNODE_NORMAL);
  463. if (Status != CR_SUCCESS) {
  464. goto Clean0;
  465. }
  466. Status = CM_Get_Device_ID(dnDevNode, szDeviceID, MAX_DEVICE_ID_LEN, 0);
  467. if (Status != CR_SUCCESS) {
  468. goto Clean0;
  469. }
  470. if (lstrcmpi(szDeviceID, TEXT("Root\\Device001\\0000")) != 0) {
  471. goto Clean0;
  472. }
  473. //---------------------------------------------------------------
  474. // 2. Test implicit local machine call using _Ex routines
  475. //---------------------------------------------------------------
  476. szDeviceID[0] = 0x0;
  477. Status = CM_Locate_DevNode_Ex(&dnDevNode, TEXT("Root\\Device001\\0000"),
  478. CM_LOCATE_DEVNODE_NORMAL, NULL);
  479. if (Status != CR_SUCCESS) {
  480. goto Clean0;
  481. }
  482. Status = CM_Get_Device_ID_Ex(dnDevNode, szDeviceID, MAX_DEVICE_ID_LEN, 0, NULL);
  483. if (Status != CR_SUCCESS) {
  484. goto Clean0;
  485. }
  486. if (lstrcmpi(szDeviceID, TEXT("Root\\Device001\\0000")) != 0) {
  487. goto Clean0;
  488. }
  489. //---------------------------------------------------------------
  490. // 3. Test connecting to NULL (local) machine
  491. //---------------------------------------------------------------
  492. Status = CM_Connect_Machine(NULL, &hMachine);
  493. if (Status != CR_SUCCESS) {
  494. goto Clean0;
  495. }
  496. szDeviceID[0] = 0x0;
  497. Status = CM_Locate_DevNode_Ex(&dnDevNode, TEXT("Root\\Device001\\0000"),
  498. CM_LOCATE_DEVNODE_NORMAL, hMachine);
  499. if (Status != CR_SUCCESS) {
  500. goto Clean0;
  501. }
  502. Status = CM_Get_Device_ID_Ex(dnDevNode, szDeviceID, MAX_DEVICE_ID_LEN,
  503. 0, hMachine);
  504. if (Status != CR_SUCCESS) {
  505. goto Clean0;
  506. }
  507. if (lstrcmpi(szDeviceID, TEXT("Root\\Device001\\0000")) != 0) {
  508. goto Clean0;
  509. }
  510. Status = CM_Disconnect_Machine(hMachine);
  511. if (Status != CR_SUCCESS) {
  512. goto Clean0;
  513. }
  514. //---------------------------------------------------------------
  515. // 4. Test explicit local machine call
  516. //---------------------------------------------------------------
  517. ulSize = MAX_PATH;
  518. GetComputerName(szComputerName, &ulSize);
  519. if (szComputerName[0] != TEXT('\\')) {
  520. TCHAR szTemp[MAX_PATH];
  521. lstrcpy(szTemp, szComputerName);
  522. lstrcpy(szComputerName, TEXT("\\\\"));
  523. lstrcat(szComputerName, szTemp);
  524. }
  525. Status = CM_Connect_Machine(szComputerName, &hMachine);
  526. if (Status != CR_SUCCESS) {
  527. goto Clean0;
  528. }
  529. szDeviceID[0] = 0x0;
  530. Status = CM_Locate_DevNode_Ex(&dnDevNode, TEXT("Root\\Device001\\0000"),
  531. CM_LOCATE_DEVNODE_NORMAL, hMachine);
  532. if (Status != CR_SUCCESS) {
  533. goto Clean0;
  534. }
  535. Status = CM_Get_Device_ID_Ex(dnDevNode, szDeviceID, MAX_DEVICE_ID_LEN,
  536. 0, hMachine);
  537. if (Status != CR_SUCCESS) {
  538. goto Clean0;
  539. }
  540. if (lstrcmpi(szDeviceID, TEXT("Root\\Device001\\0000")) != 0) {
  541. goto Clean0;
  542. }
  543. Status = CM_Disconnect_Machine(hMachine);
  544. if (Status != CR_SUCCESS) {
  545. goto Clean0;
  546. }
  547. //---------------------------------------------------------------
  548. // 5. Test remote machine call
  549. //---------------------------------------------------------------
  550. Status = CM_Connect_Machine(TEXT("\\\\PAULAT_PPC1X"), &hMachine);
  551. if (Status != CR_SUCCESS) {
  552. goto Clean0;
  553. }
  554. szDeviceID[0] = 0x0;
  555. Status = CM_Locate_DevNode_Ex(&dnDevNode, TEXT("Root\\Device001\\0000"),
  556. CM_LOCATE_DEVNODE_NORMAL, hMachine);
  557. if (Status != CR_SUCCESS) {
  558. goto Clean0;
  559. }
  560. Status = CM_Get_Device_ID_Ex(dnDevNode, szDeviceID, MAX_DEVICE_ID_LEN,
  561. 0, hMachine);
  562. if (Status != CR_SUCCESS) {
  563. goto Clean0;
  564. }
  565. if (lstrcmpi(szDeviceID, TEXT("Root\\Device001\\0000")) != 0) {
  566. goto Clean0;
  567. }
  568. Status = CM_Disconnect_Machine(hMachine);
  569. if (Status != CR_SUCCESS) {
  570. goto Clean0;
  571. }
  572. Clean0:
  573. if (Status == CR_SUCCESS) {
  574. MessageBox(hWnd, TEXT("Connect Test Passed"), TEXT("Connect Test"), MB_OK);
  575. } else {
  576. MessageBox(hWnd, TEXT("Connect Test Failed"), TEXT("Connect Test"), MB_OK);
  577. }
  578. return;
  579. } // ConnectTest
  580. BOOL
  581. CALLBACK
  582. AddPropSheetPageProc(
  583. IN HPROPSHEETPAGE hpage,
  584. IN LPARAM lParam
  585. )
  586. {
  587. *((HPROPSHEETPAGE *)lParam) = hpage;
  588. return TRUE;
  589. }
  590. VOID
  591. CallPnPIsaDetect(
  592. HWND hDlg,
  593. LPTSTR pszDevice
  594. )
  595. {
  596. HMODULE hLib = NULL;
  597. SP_DEVINFO_DATA DeviceInfoData;
  598. HDEVINFO hDevInfo;
  599. FARPROC PropSheetExtProc;
  600. PROPSHEETHEADER PropHeader;
  601. HPROPSHEETPAGE hPages[2];
  602. SP_PROPSHEETPAGE_REQUEST PropParams;
  603. #if 0
  604. hLib = LoadLibrary(TEXT("setupapi.dll"));
  605. fproc = GetProcAddress(hLib, TEXT("DbgSelectDeviceResources"));
  606. Status = (fproc)(pszDevice);
  607. FreeLibrary(hLib);
  608. #endif
  609. //
  610. // Create a device info element and device info data set.
  611. //
  612. hDevInfo = SetupDiCreateDeviceInfoList(NULL, NULL);
  613. if (hDevInfo == INVALID_HANDLE_VALUE) {
  614. goto Clean0;
  615. }
  616. DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  617. if (!SetupDiOpenDeviceInfo(hDevInfo,
  618. pszDevice,
  619. NULL,
  620. 0,
  621. &DeviceInfoData)) {
  622. goto Clean0;
  623. }
  624. //
  625. // Now get the resource selection page from setupapi.dll
  626. //
  627. if(!(hLib = GetModuleHandle(TEXT("setupapi.dll"))) ||
  628. !(PropSheetExtProc = GetProcAddress(hLib, "ExtensionPropSheetPageProc"))) {
  629. goto Clean0;
  630. }
  631. PropParams.cbSize = sizeof(SP_PROPSHEETPAGE_REQUEST);
  632. PropParams.PageRequested = SPPSR_SELECT_DEVICE_RESOURCES;
  633. PropParams.DeviceInfoSet = hDevInfo;
  634. PropParams.DeviceInfoData = &DeviceInfoData;
  635. if(!PropSheetExtProc(&PropParams, AddPropSheetPageProc, &hPages[0])) {
  636. goto Clean0;
  637. }
  638. //
  639. // create the property sheet
  640. //
  641. PropHeader.dwSize = sizeof(PROPSHEETHEADER);
  642. PropHeader.dwFlags = PSH_PROPTITLE | PSH_NOAPPLYNOW;
  643. PropHeader.hwndParent = NULL;
  644. PropHeader.hInstance = hInst;
  645. PropHeader.pszIcon = NULL;
  646. PropHeader.pszCaption = L"Device";
  647. PropHeader.nPages = 1;
  648. PropHeader.phpage = hPages;
  649. PropHeader.nStartPage = 0;
  650. PropHeader.pfnCallback = NULL;
  651. PropertySheet(&PropHeader);
  652. SetupDiDestroyDeviceInfoList(hDevInfo);
  653. Clean0:
  654. ;
  655. return;
  656. } // CallPnPIsaDetect
  657. VOID
  658. DumpDeviceChangeData(
  659. HWND hWnd,
  660. WPARAM wParam,
  661. LPARAM lParam
  662. )
  663. {
  664. TCHAR szDbg[MAX_PATH];
  665. OutputDebugString(TEXT("CMTEST: WM_DEVICECHANGE message received\n"));
  666. switch (wParam) {
  667. case DBT_DEVICEARRIVAL:
  668. OutputDebugString(TEXT(" DBT_DEVICEARRIVAL event\n"));
  669. break;
  670. case DBT_DEVICEREMOVECOMPLETE:
  671. OutputDebugString(TEXT(" DBT_DEVICEREMOVECOMPLETE event\n"));
  672. break;
  673. case DBT_DEVICEQUERYREMOVE:
  674. OutputDebugString(TEXT(" DBT_DEVICEQUERYREMOVE event\n"));
  675. break;
  676. case DBT_DEVICEQUERYREMOVEFAILED:
  677. OutputDebugString(TEXT(" DBT_DEVICEQUERYREMOVEFAILED event\n"));
  678. break;
  679. case DBT_DEVICEREMOVEPENDING:
  680. OutputDebugString(TEXT(" DBT_DEVICEREMOVEPENDING event\n"));
  681. break;
  682. case DBT_DEVICETYPESPECIFIC:
  683. OutputDebugString(TEXT(" DBT_DEVICETYPESPECIFIC event\n"));
  684. break;
  685. case DBT_CUSTOMEVENT:
  686. OutputDebugString(TEXT(" DBT_CUSTOMEVENT event\n"));
  687. break;
  688. default:
  689. break;
  690. }
  691. switch (((PDEV_BROADCAST_HDR)lParam)->dbch_devicetype) {
  692. case DBT_DEVTYP_DEVICEINTERFACE: {
  693. PDEV_BROADCAST_DEVICEINTERFACE p = (PDEV_BROADCAST_DEVICEINTERFACE)lParam;
  694. LPTSTR pString;
  695. OutputDebugString(TEXT(" DBT_DEVTYP_DEVICEINTERFACE\n"));
  696. wsprintf(szDbg, TEXT(" %s\n"), p->dbcc_name);
  697. OutputDebugString(szDbg);
  698. UuidToString(&p->dbcc_classguid, &pString);
  699. wsprintf(szDbg, TEXT(" %s\n"), pString);
  700. OutputDebugString(szDbg);
  701. break;
  702. }
  703. case DBT_DEVTYP_HANDLE:
  704. OutputDebugString(TEXT(" DBT_DEVTYP_HANDLE\n"));
  705. break;
  706. default:
  707. break;
  708. }
  709. wsprintf(szDbg, TEXT(" wParam = %d\n"));
  710. OutputDebugString(szDbg);
  711. } // DumpDeviceChangeData