Leaked source code of windows server 2003
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.

387 lines
7.7 KiB

  1. #ifndef __API_H__
  2. #define __API_H__
  3. /*++
  4. Copyright (C) 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. BOOL
  17. DeviceManager_ExecuteA(
  18. HWND hwndStub,
  19. HINSTANCE hAppInstance,
  20. LPCSTR lpMachineName,
  21. int nCmdShow
  22. );
  23. STDAPI_(BOOL)
  24. DeviceManager_ExecuteW(
  25. HWND hwndStub,
  26. HINSTANCE hAppInstance,
  27. LPCWSTR lpMachineName,
  28. int nCmdShow
  29. );
  30. BOOL
  31. DeviceManager_Execute(
  32. HWND hwndStub,
  33. HINSTANCE hAppInstance,
  34. LPCTSTR lpMachineName,
  35. int nCmdShow
  36. );
  37. STDAPI_(void)
  38. DeviceProperties_RunDLLA(
  39. HWND hwndStub,
  40. HINSTANCE hAppInstance,
  41. LPSTR lpCmdLine,
  42. int nCmdShow
  43. );
  44. STDAPI_(void)
  45. DeviceProperties_RunDLLW(
  46. HWND hwndStub,
  47. HINSTANCE hAppInstance,
  48. LPWSTR lpCmdLine,
  49. int nCmdShow
  50. );
  51. STDAPI_(int)
  52. DevicePropertiesExA(
  53. HWND hwndParent,
  54. LPCSTR MachineName,
  55. LPCSTR DeviceID,
  56. DWORD Flags,
  57. BOOL ShowDeviceTree
  58. );
  59. STDAPI_(int)
  60. DevicePropertiesExW(
  61. HWND hwndParent,
  62. LPCWSTR MachineName,
  63. LPCWSTR DeviceID,
  64. DWORD Flags,
  65. BOOL ShowDeviceTree
  66. );
  67. STDAPI_(int)
  68. DevicePropertiesA(
  69. HWND hwndParent,
  70. LPCSTR MachineName,
  71. LPCSTR DeviceID,
  72. BOOL ShowDeviceTree
  73. );
  74. STDAPI_(int)
  75. DevicePropertiesW(
  76. HWND hwndParent,
  77. LPCWSTR MachineName,
  78. LPCWSTR DeviceID,
  79. BOOL ShowDeviceTree
  80. );
  81. //
  82. // DevicePropertiesEx Flags
  83. //
  84. #define DEVPROP_SHOW_RESOURCE_TAB 0x00000001
  85. #define DEVPROP_LAUNCH_TROUBLESHOOTER 0x00000002
  86. #define DEVPROP_BITS 0x00000003
  87. STDAPI_(UINT)
  88. DeviceProblemTextA(
  89. HMACHINE hMachine,
  90. DEVNODE DevNode,
  91. ULONG ProblemNumber,
  92. LPSTR Buffer,
  93. UINT BufferSize
  94. );
  95. STDAPI_(UINT)
  96. DeviceProblemTextW(
  97. HMACHINE hMachine,
  98. DEVNODE DevNode,
  99. ULONG ProblemNumber,
  100. LPWSTR Buffer,
  101. UINT BufferSize
  102. );
  103. //////////////////////////////////////////////////////////////////////////
  104. ////////
  105. ////////
  106. ///////
  107. const TCHAR* MMC_FILE = TEXT("mmc.exe");
  108. const TCHAR* DEVMGR_MSC_FILE = TEXT("devmgmt.msc");
  109. const TCHAR* MMC_COMMAND_LINE = TEXT(" /s ");
  110. const TCHAR* DEVMGR_MACHINENAME_OPTION = TEXT(" /dmmachinename %s");
  111. const TCHAR* DEVMGR_DEVICEID_OPTION = TEXT(" /dmdeviceid %s");
  112. const TCHAR* DEVMGR_COMMAND_OPTION = TEXT(" /dmcommand %s");
  113. const TCHAR* DEVMGR_CMD_PROPERTY = TEXT("property");
  114. const TCHAR* RUNDLL_MACHINENAME = TEXT("machinename");
  115. const TCHAR* RUNDLL_DEVICEID = TEXT("deviceid");
  116. const TCHAR* RUNDLL_SHOWDEVICETREE = TEXT("showdevicetree");
  117. const TCHAR* RUNDLL_FLAGS = TEXT("flags");
  118. void
  119. ReportCmdLineError(
  120. HWND hwndParent,
  121. int ErrorStringID,
  122. LPCTSTR Caption = NULL
  123. );
  124. BOOL AddPageCallback(
  125. HPROPSHEETPAGE hPage,
  126. LPARAM lParam
  127. );
  128. int
  129. PropertyRunDeviceTree(
  130. HWND hwndParent,
  131. LPCTSTR MachineName,
  132. LPCTSTR DeviceID
  133. );
  134. int
  135. DevicePropertiesEx(
  136. HWND hwndParent,
  137. LPCTSTR MachineName,
  138. LPCTSTR DeviceID,
  139. DWORD Flags,
  140. BOOL ShowDeviceTree
  141. );
  142. void
  143. DeviceProperties_RunDLL(
  144. HWND hwndStub,
  145. HINSTANCE hAppInstance,
  146. LPCTSTR lpCmdLine,
  147. int nCmdShow
  148. );
  149. int
  150. DeviceAdvancedPropertiesA(
  151. HWND hwndParent,
  152. LPCSTR MachineName,
  153. LPCSTR DeviceId
  154. );
  155. STDAPI_(int)
  156. DeviceAdvancedPropertiesW(
  157. HWND hwndParent,
  158. LPCWSTR MachineName,
  159. LPCWSTR DeviceId
  160. );
  161. int
  162. DeviceAdvancedProperties(
  163. HWND hwndParent,
  164. LPCTSTR MachineName,
  165. LPCTSTR DeviceId
  166. );
  167. void
  168. DeviceProblenWizard_RunDLLA(
  169. HWND hwndStub,
  170. HINSTANCE hAppInstance,
  171. LPCTSTR lpCmdLine,
  172. int nCmdShow
  173. );
  174. void
  175. DeviceProblenWizard_RunDLLW(
  176. HWND hwndStub,
  177. HINSTANCE hAppInstance,
  178. LPCTSTR lpCmdLine,
  179. int nCmdShow
  180. );
  181. void
  182. DeviceProblenWizard_RunDLL(
  183. HWND hwndStub,
  184. HINSTANCE hAppInstance,
  185. LPCTSTR lpCmdLine,
  186. int nCmdShow
  187. );
  188. STDAPI_(int)
  189. DeviceProblemWizardA(
  190. HWND hwndParent,
  191. LPCSTR MachineName,
  192. LPCSTR DeviceId
  193. );
  194. STDAPI_(int)
  195. DeviceProblemWizardW(
  196. HWND hwndParent,
  197. LPCWSTR MachineName,
  198. LPCWSTR DeviceId
  199. );
  200. int
  201. DeviceProblemWizard(
  202. HWND hwndParent,
  203. LPCTSTR MachineName,
  204. LPCTSTR DeviceId
  205. );
  206. //
  207. // Object to parse command line passed in the lpCmdLine parameter
  208. // passed in DeviceProperties_RunDLL APIs
  209. //
  210. class CRunDLLCommandLine : public CCommandLine
  211. {
  212. public:
  213. CRunDLLCommandLine() : m_ShowDeviceTree(FALSE), m_Flags(0), m_WaitMachineName(FALSE),
  214. m_WaitDeviceID(FALSE), m_WaitFlags(FALSE)
  215. {}
  216. virtual void ParseParam(LPCTSTR Param, BOOL bFlag)
  217. {
  218. if (bFlag)
  219. {
  220. if (!lstrcmpi(RUNDLL_MACHINENAME, Param))
  221. {
  222. m_WaitMachineName = TRUE;
  223. }
  224. if (!lstrcmpi(RUNDLL_DEVICEID, Param))
  225. {
  226. m_WaitDeviceID = TRUE;
  227. }
  228. if (!lstrcmpi(RUNDLL_SHOWDEVICETREE, Param))
  229. {
  230. m_ShowDeviceTree = TRUE;
  231. }
  232. if (!lstrcmpi(RUNDLL_FLAGS, Param)) {
  233. m_WaitFlags = TRUE;
  234. }
  235. }
  236. else
  237. {
  238. if (m_WaitMachineName)
  239. {
  240. m_strMachineName = Param;
  241. m_WaitMachineName = FALSE;
  242. }
  243. if (m_WaitDeviceID)
  244. {
  245. m_strDeviceID = Param;
  246. m_WaitDeviceID = FALSE;
  247. }
  248. if (m_WaitFlags) {
  249. m_Flags = (DWORD)StrToInt(Param);
  250. m_WaitFlags = FALSE;
  251. }
  252. }
  253. }
  254. LPCTSTR GetMachineName()
  255. {
  256. return (m_strMachineName.IsEmpty()) ? NULL : (LPCTSTR)m_strMachineName;
  257. }
  258. LPCTSTR GetDeviceID()
  259. {
  260. return (m_strDeviceID.IsEmpty()) ? NULL : (LPCTSTR)m_strDeviceID;
  261. }
  262. BOOL ToShowDeviceTree()
  263. {
  264. return m_ShowDeviceTree;
  265. }
  266. DWORD GetFlags()
  267. {
  268. return m_Flags;
  269. }
  270. private:
  271. BOOL m_WaitMachineName;
  272. BOOL m_WaitDeviceID;
  273. BOOL m_WaitFlags;
  274. String m_strDeviceID;
  275. String m_strMachineName;
  276. BOOL m_ShowDeviceTree;
  277. DWORD m_Flags;
  278. };
  279. //
  280. // Object to return the corresponding LPTSTR for the given
  281. // string.
  282. //
  283. class CTString
  284. {
  285. public:
  286. CTString(LPCWSTR pWString);
  287. CTString(LPCSTR pString);
  288. ~CTString()
  289. {
  290. if (m_Allocated && m_pTString)
  291. {
  292. delete [] m_pTString;
  293. }
  294. }
  295. operator LPCTSTR()
  296. {
  297. return (LPCTSTR)m_pTString;
  298. }
  299. private:
  300. LPTSTR m_pTString;
  301. BOOL m_Allocated;
  302. };
  303. CTString::CTString(
  304. LPCWSTR pWString
  305. )
  306. {
  307. m_pTString = NULL;
  308. m_Allocated = FALSE;
  309. m_pTString = (LPTSTR)pWString;
  310. }
  311. CTString::CTString(
  312. LPCSTR pAString
  313. )
  314. {
  315. m_pTString = NULL;
  316. m_Allocated = FALSE;
  317. int aLen = pAString ? (int)strlen(pAString) : 0;
  318. if (aLen)
  319. {
  320. int tLen;
  321. tLen = MultiByteToWideChar(CP_ACP, 0, pAString, aLen, NULL, 0);
  322. if (tLen)
  323. {
  324. m_pTString = new TCHAR[tLen + 1];
  325. MultiByteToWideChar(CP_ACP, 0, pAString, aLen, m_pTString, tLen);
  326. m_pTString[tLen] = _T('\0');
  327. }
  328. m_Allocated = TRUE;
  329. }
  330. }
  331. #endif // __API_H__