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.

542 lines
13 KiB

  1. #ifndef __API_H__
  2. #define __API_H__
  3. /*++
  4. Copyright (C) 1997-1999 Microsoft Corporation
  5. Module Name:
  6. api.h
  7. Abstract:
  8. header file for api.cpp
  9. Note that no other file can #include "api.h" because the file contains
  10. definitions, not just declarations.
  11. Author:
  12. William Hsieh (williamh) created
  13. Revision History:
  14. --*/
  15. // Exported APIs
  16. // This function launches Device Manager as a separate process.
  17. // This function is provided for any application who wants to
  18. // launch Device Manager but do not want to know the detail about
  19. // MMC.
  20. //
  21. // INPUT: HWND hwndParent -- the Window Handle of the caller.
  22. // HINSTANCE hInstance -- The caller's module instance handle
  23. // LPCTSTR lpMachineName -- optional machine name. NULL for local machine.
  24. // int nCmdShow -- controlling how the Device Manager window
  25. // to be shown. Refer to Windows API
  26. // reference manual for detail.
  27. // OUTPUT: TRUE if the process is created successfully.
  28. // FALSE if the process is not created. Use GetLastError()
  29. // API to retreive error code.
  30. BOOL
  31. DeviceManager_ExecuteA(
  32. HWND hwndStub,
  33. HINSTANCE hAppInstance,
  34. LPCSTR lpMachineName,
  35. int nCmdShow
  36. );
  37. STDAPI_(BOOL)
  38. DeviceManager_ExecuteW(
  39. HWND hwndStub,
  40. HINSTANCE hAppInstance,
  41. LPCWSTR lpMachineName,
  42. int nCmdShow
  43. );
  44. BOOL
  45. DeviceManager_Execute(
  46. HWND hwndStub,
  47. HINSTANCE hAppInstance,
  48. LPCTSTR lpMachineName,
  49. int nCmdShow
  50. );
  51. // This API parses the given command line, creates a property sheet
  52. // for the device ID specified in the command line and
  53. // displays the property sheet.
  54. //
  55. // The command line syntax is:
  56. // /deviceid <DeviceID> [/machinename <Machine Name>] [/showdevicetree]
  57. //
  58. // <DeviceID> specifiec the target device
  59. // <MachineName> specifies the optional computer name.
  60. // ShowDeviceTree, if specifies indicates that device tree should be displayed.
  61. //
  62. STDAPI_(void)
  63. DeviceProperties_RunDLLA(
  64. HWND hwndStub,
  65. HINSTANCE hAppInstance,
  66. LPSTR lpCmdLine,
  67. int nCmdShow
  68. );
  69. STDAPI_(void)
  70. DeviceProperties_RunDLLW(
  71. HWND hwndStub,
  72. HINSTANCE hAppInstance,
  73. LPWSTR lpCmdLine,
  74. int nCmdShow
  75. );
  76. // This function creates and display a property sheet for the given device
  77. // if a valid device id is given. It can also display the device tree
  78. // in the same time(with or without property sheet display).
  79. //
  80. // INPUT: HWND hwndParent -- the Window Handle of the caller.
  81. // LPCTSTR MachineName -- optional machine name. If not specified
  82. // local machine is used.
  83. // LPCTSTR DeviceId -- the device ID. Must be provided if
  84. // ShowDeviceTree is FALSE, otherwise,
  85. // this function returns 0 and the last
  86. // error is ERROR_INVALID_PARAMETER
  87. // DWORD Flags --
  88. // BOOL ShowDeviceTree -- TRUE if to shwo device tree
  89. // OUTPUT:
  90. // 0 if error, call GetLastError API to retrieve the error code.
  91. // 1 if succeeded.
  92. // This function will not return to the caller until the property
  93. // sheet(or the device tree, if requested) dismissed.
  94. STDAPI_(int)
  95. DevicePropertiesExA(
  96. HWND hwndParent,
  97. LPCSTR MachineName,
  98. LPCSTR DeviceID,
  99. DWORD Flags,
  100. BOOL ShowDeviceTree
  101. );
  102. STDAPI_(int)
  103. DevicePropertiesExW(
  104. HWND hwndParent,
  105. LPCWSTR MachineName,
  106. LPCWSTR DeviceID,
  107. DWORD Flags,
  108. BOOL ShowDeviceTree
  109. );
  110. STDAPI_(int)
  111. DevicePropertiesA(
  112. HWND hwndParent,
  113. LPCSTR MachineName,
  114. LPCSTR DeviceID,
  115. BOOL ShowDeviceTree
  116. );
  117. STDAPI_(int)
  118. DevicePropertiesW(
  119. HWND hwndParent,
  120. LPCWSTR MachineName,
  121. LPCWSTR DeviceID,
  122. BOOL ShowDeviceTree
  123. );
  124. //
  125. // DevicePropertiesEx Flags
  126. //
  127. #define DEVPROP_SHOW_RESOURCE_TAB 0x00000001
  128. #define DEVPROP_LAUNCH_TROUBLESHOOTER 0x00000002
  129. #define DEVPROP_BITS 0x00000003
  130. // This function returns the appropriate problem text based on the given
  131. // device and problem number.
  132. //
  133. // INPUT: HMACHINE hMachine -- Machine handle, NULL for local machine
  134. // DEVNODE DevNode -- The device. This paramter is required.
  135. // ULONG ProblemNumber -- The CM problem number
  136. // LPTSTR Buffer -- Buffer to receive the text.
  137. // UINT BufferSize -- Buffer size in chars
  138. // OUTPUT:
  139. // 0 if the function failed. Call GetLastError API to retreive the
  140. // error code.
  141. // <> 0 The required buffer size in chars to receive the text.
  142. // not including the NULL termianted char.
  143. // The caller should check this value to decide it has provided
  144. // enough buffer. ERROR_INSUFFICIENT_BUFFER is not set
  145. // in this function
  146. STDAPI_(UINT)
  147. DeviceProblemTextA(
  148. HMACHINE hMachine,
  149. DEVNODE DevNode,
  150. ULONG ProblemNumber,
  151. LPSTR Buffer,
  152. UINT BufferSize
  153. );
  154. STDAPI_(UINT)
  155. DeviceProblemTextW(
  156. HMACHINE hMachine,
  157. DEVNODE DevNode,
  158. ULONG ProblemNumber,
  159. LPWSTR Buffer,
  160. UINT BufferSize
  161. );
  162. // This function prints the machine's hardware report
  163. //
  164. // INPUT: LPCTSTR MachineName -- The machine name. NULL for local machine
  165. // LPCTSTR FileName -- The file name to which the report
  166. // will be written to. If the file already
  167. // exist, this function return FALSE.
  168. // The caller should delete the file and
  169. // call the function again.
  170. // int ReportType -- 0 -- print system summary
  171. // 1 -- print selected classes
  172. // 2 -- print all
  173. // DWORD ClassGuids -- number of class guid are in ClassGuidList
  174. // Only required if ReportType is 1
  175. // LPGUID ClassGuidList -- class guid list. Only required if
  176. // ReportType is 1.
  177. // OUTPUT:
  178. // TRUE if the function succeeded.
  179. // FLASE if the function failed. GetLastError() returns the error code
  180. //
  181. //
  182. //
  183. // error code.
  184. // <> 0 The required buffer size in chars to receive the text.
  185. // not including the NULL termianted char.
  186. // The caller should check this value to decide it has provided
  187. // enough buffer. ERROR_INSUFFICIENT_BUFFER is not set
  188. // in this function
  189. STDAPI_(BOOL)
  190. DeviceManagerPrintA(
  191. LPCSTR MachineName,
  192. LPCSTR FileName,
  193. int ReportType,
  194. DWORD ClassGuids,
  195. LPGUID ClassGuidList
  196. );
  197. STDAPI_(BOOL)
  198. DeviceManagerPrintW(
  199. LPCWSTR MachineName,
  200. LPCWSTR FileName,
  201. int ReportType,
  202. DWORD ClassGuids,
  203. LPGUID ClassGuidList
  204. );
  205. BOOL
  206. DeviceManagerDoPrint(
  207. LPCTSTR MachineName,
  208. LPCTSTR FileName,
  209. int ReportType,
  210. DWORD ClassGuids,
  211. LPGUID ClassGuidList
  212. );
  213. //////////////////////////////////////////////////////////////////////////
  214. ////////
  215. ////////
  216. ///////
  217. const TCHAR* MMC_FILE = TEXT("mmc.exe");
  218. const TCHAR* DEVMGR_MSC_FILE = TEXT("devmgmt.msc");
  219. const TCHAR* MMC_COMMAND_LINE = TEXT(" /s ");
  220. const TCHAR* DEVMGR_MACHINENAME_OPTION = TEXT(" /dmmachinename %s");
  221. const TCHAR* DEVMGR_DEVICEID_OPTION = TEXT(" /dmdeviceid %s");
  222. const TCHAR* DEVMGR_COMMAND_OPTION = TEXT(" /dmcommand %s");
  223. const TCHAR* DEVMGR_CMD_PROPERTY = TEXT("property");
  224. const TCHAR* RUNDLL_MACHINENAME = TEXT("machinename");
  225. const TCHAR* RUNDLL_DEVICEID = TEXT("deviceid");
  226. const TCHAR* RUNDLL_SHOWDEVICETREE = TEXT("showdevicetree");
  227. const TCHAR* RUNDLL_FLAGS = TEXT("flags");
  228. void
  229. ReportCmdLineError(
  230. HWND hwndParent,
  231. int ErrorStringID,
  232. LPCTSTR Caption = NULL
  233. );
  234. BOOL AddPageCallback(
  235. HPROPSHEETPAGE hPage,
  236. LPARAM lParam
  237. );
  238. int
  239. PropertyRunDeviceTree(
  240. HWND hwndParent,
  241. LPCTSTR MachineName,
  242. LPCTSTR DeviceID
  243. );
  244. int
  245. DevicePropertiesEx(
  246. HWND hwndParent,
  247. LPCTSTR MachineName,
  248. LPCTSTR DeviceID,
  249. DWORD Flags,
  250. BOOL ShowDeviceTree
  251. );
  252. void
  253. DeviceProperties_RunDLL(
  254. HWND hwndStub,
  255. HINSTANCE hAppInstance,
  256. LPCTSTR lpCmdLine,
  257. int nCmdShow
  258. );
  259. int
  260. DeviceAdvancedPropertiesA(
  261. HWND hwndParent,
  262. LPCSTR MachineName,
  263. LPCSTR DeviceId
  264. );
  265. STDAPI_(int)
  266. DeviceAdvancedPropertiesW(
  267. HWND hwndParent,
  268. LPCWSTR MachineName,
  269. LPCWSTR DeviceId
  270. );
  271. int
  272. DeviceAdvancedProperties(
  273. HWND hwndParent,
  274. LPCTSTR MachineName,
  275. LPCTSTR DeviceId
  276. );
  277. void
  278. DeviceProblenWizard_RunDLLA(
  279. HWND hwndStub,
  280. HINSTANCE hAppInstance,
  281. LPCTSTR lpCmdLine,
  282. int nCmdShow
  283. );
  284. void
  285. DeviceProblenWizard_RunDLLW(
  286. HWND hwndStub,
  287. HINSTANCE hAppInstance,
  288. LPCTSTR lpCmdLine,
  289. int nCmdShow
  290. );
  291. void
  292. DeviceProblenWizard_RunDLL(
  293. HWND hwndStub,
  294. HINSTANCE hAppInstance,
  295. LPCTSTR lpCmdLine,
  296. int nCmdShow
  297. );
  298. // This function brings up the troubleshooter for the specified
  299. // DeviceId.
  300. //
  301. // INPUT: HWND hwndParent -- the Window Handle of the caller.
  302. // LPCTSTR MachineName -- optional machine name. If not specified
  303. // local machine is used.
  304. // LPCTSTR DeviceId -- the device ID. Must be provided.
  305. // OUTPUT:
  306. // 0 if error, call GetLastError API to retrieve the error code.
  307. // 1 if succeeded.
  308. STDAPI_(int)
  309. DeviceProblemWizardA(
  310. HWND hwndParent,
  311. LPCSTR MachineName,
  312. LPCSTR DeviceId
  313. );
  314. STDAPI_(int)
  315. DeviceProblemWizardW(
  316. HWND hwndParent,
  317. LPCWSTR MachineName,
  318. LPCWSTR DeviceId
  319. );
  320. int
  321. DeviceProblemWizard(
  322. HWND hwndParent,
  323. LPCTSTR MachineName,
  324. LPCTSTR DeviceId
  325. );
  326. // Object to parse command line passed in the lpCmdLine parameter
  327. // passed in DeviceProperties_RunDLL APIs
  328. //
  329. class CRunDLLCommandLine : public CCommandLine
  330. {
  331. public:
  332. CRunDLLCommandLine() : m_ShowDeviceTree(FALSE), m_Flags(0), m_WaitMachineName(FALSE),
  333. m_WaitDeviceID(FALSE), m_WaitFlags(FALSE)
  334. {}
  335. virtual void ParseParam(LPCTSTR Param, BOOL bFlag, BOOL bLast)
  336. {
  337. if (bFlag)
  338. {
  339. if (!lstrcmpi(RUNDLL_MACHINENAME, Param))
  340. {
  341. m_WaitMachineName = TRUE;
  342. }
  343. if (!lstrcmpi(RUNDLL_DEVICEID, Param))
  344. {
  345. m_WaitDeviceID = TRUE;
  346. }
  347. if (!lstrcmpi(RUNDLL_SHOWDEVICETREE, Param))
  348. {
  349. m_ShowDeviceTree = TRUE;
  350. }
  351. if (!lstrcmpi(RUNDLL_FLAGS, Param)) {
  352. m_WaitFlags = TRUE;
  353. }
  354. }
  355. else
  356. {
  357. if (m_WaitMachineName)
  358. {
  359. m_strMachineName = Param;
  360. m_WaitMachineName = FALSE;
  361. }
  362. if (m_WaitDeviceID)
  363. {
  364. m_strDeviceID = Param;
  365. m_WaitDeviceID = FALSE;
  366. }
  367. if (m_WaitFlags) {
  368. m_Flags = (DWORD)StrToInt(Param);
  369. m_WaitFlags = FALSE;
  370. }
  371. }
  372. }
  373. LPCTSTR GetMachineName()
  374. {
  375. return (m_strMachineName.IsEmpty()) ? NULL : (LPCTSTR)m_strMachineName;
  376. }
  377. LPCTSTR GetDeviceID()
  378. {
  379. return (m_strDeviceID.IsEmpty()) ? NULL : (LPCTSTR)m_strDeviceID;
  380. }
  381. BOOL ToShowDeviceTree()
  382. {
  383. return m_ShowDeviceTree;
  384. }
  385. DWORD GetFlags()
  386. {
  387. return m_Flags;
  388. }
  389. private:
  390. BOOL m_WaitMachineName;
  391. BOOL m_WaitDeviceID;
  392. BOOL m_WaitFlags;
  393. String m_strDeviceID;
  394. String m_strMachineName;
  395. BOOL m_ShowDeviceTree;
  396. DWORD m_Flags;
  397. };
  398. //
  399. // Object to return the corresponding LPTSTR for the given
  400. // string.
  401. //
  402. class CTString
  403. {
  404. public:
  405. CTString(LPCWSTR pWString);
  406. CTString(LPCSTR pString);
  407. ~CTString()
  408. {
  409. if (m_Allocated && m_pTString)
  410. {
  411. delete [] m_pTString;
  412. }
  413. }
  414. operator LPCTSTR()
  415. {
  416. return (LPCTSTR)m_pTString;
  417. }
  418. private:
  419. LPTSTR m_pTString;
  420. BOOL m_Allocated;
  421. };
  422. CTString::CTString(
  423. LPCWSTR pWString
  424. )
  425. {
  426. m_pTString = NULL;
  427. m_Allocated = FALSE;
  428. #ifdef UNICODE
  429. m_pTString = (LPTSTR)pWString;
  430. #else
  431. int wLen = pWString ? wcslen(pWString) : 0;
  432. if (wLen)
  433. {
  434. int tLen;
  435. tLen = WideCharToMultiByte(CP_ACP, 0, pWString, wLen, NULL, 0, NULL, NULL);
  436. if (tLen)
  437. {
  438. m_pTString = new TCHAR[tLen + 1];
  439. WideCharToMultiByte(CP_ACP, 0, pWString, wLen, m_pTString, tLen, NULL, NULL);
  440. m_pTString[tLen] = _T('\0');
  441. }
  442. m_Allocated = TRUE;
  443. }
  444. #endif
  445. }
  446. CTString::CTString(
  447. LPCSTR pAString
  448. )
  449. {
  450. m_pTString = NULL;
  451. m_Allocated = FALSE;
  452. #ifndef UNICODE
  453. m_pTString = (LPTSTR)pAString;
  454. #else
  455. int aLen = pAString ? strlen(pAString) : 0;
  456. if (aLen)
  457. {
  458. int tLen;
  459. tLen = MultiByteToWideChar(CP_ACP, 0, pAString, aLen, NULL, 0);
  460. if (tLen)
  461. {
  462. m_pTString = new TCHAR[tLen + 1];
  463. MultiByteToWideChar(CP_ACP, 0, pAString, aLen, m_pTString, tLen);
  464. m_pTString[tLen] = _T('\0');
  465. }
  466. m_Allocated = TRUE;
  467. }
  468. #endif
  469. }
  470. #endif // __API_H__