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.

420 lines
13 KiB

  1. //
  2. // MODULE: TSLaunchDLL.cpp
  3. //
  4. // PURPOSE: The functions that are exported by TSLauncher.dll.
  5. //
  6. // PROJECT: Local Troubleshooter Launcher for the Device Manager
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-633-4743 [email protected]
  9. //
  10. // AUTHORS: Joe Mabel and Richard Meadows
  11. // COMMENTS BY: Joe Mabel
  12. //
  13. // ORIGINAL DATE: 2-26-98
  14. //
  15. //
  16. // Version Date By Comments
  17. //--------------------------------------------------------------------
  18. // V0.1 - RM Original
  19. ///////////////////////
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #include <winnt.h>
  23. #include <ole2.h>
  24. #include "TSLError.h"
  25. #define __TSLAUNCHER 1
  26. #include <TSLauncher.h>
  27. #include "ShortList.h"
  28. #include "LaunchServ_i.c"
  29. #include "LaunchServ.h"
  30. #include <comdef.h>
  31. #include "Properties.h"
  32. #include "Launchers.h"
  33. #include <objbase.h>
  34. static int g_NextHandle = 1;
  35. static CShortList g_unkList;
  36. HINSTANCE g_hInst;
  37. BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  38. {
  39. switch(fdwReason)
  40. {
  41. case DLL_PROCESS_ATTACH:
  42. g_hInst = hinstDLL;
  43. break;
  44. case DLL_PROCESS_DETACH :
  45. case DLL_THREAD_DETACH :
  46. // g_unkList.RemoveAll(); This causes an access violation if the list is not already empty.
  47. // Saltmine Creative should not be providing a library that uses a com object.
  48. // Saltmine Creative should be providing com objects and not this legacy dll.
  49. break;
  50. }
  51. return TRUE;
  52. }
  53. /* TSLOpen
  54. Returns a handle that should be passed into subsequent Troubleshooter Launcher calls
  55. as hTSL. Returns NULL handle on failure. (Should only fail on out of memory,
  56. probably will never arise.)
  57. */
  58. HANDLE WINAPI TSLOpen()
  59. {
  60. HRESULT hRes;
  61. CLSID clsidLaunchTS = CLSID_TShootATL;
  62. IID iidLaunchTS = IID_ITShootATL;
  63. HANDLE hResult = (HANDLE) g_NextHandle;
  64. ITShootATL *pITShootATL = NULL;
  65. hRes = CoCreateInstance(clsidLaunchTS, NULL,
  66. CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER | CLSCTX_INPROC_SERVER,
  67. iidLaunchTS, (void **) &pITShootATL);
  68. if (FAILED(hRes))
  69. {
  70. hResult = NULL;
  71. }
  72. else
  73. {
  74. if (g_unkList.Add(hResult, pITShootATL))
  75. g_NextHandle++;
  76. else
  77. hResult = NULL;
  78. }
  79. return hResult;
  80. }
  81. /* TSLClose
  82. Closes handle. Returns TSL_OK (== 0) if handle was open, otherwise TSL_ERROR_BAD_HANDLE.
  83. */
  84. DWORD WINAPI TSLClose (HANDLE hTSL)
  85. {
  86. DWORD dwResult = TSL_OK;
  87. if (!g_unkList.Remove(hTSL))
  88. dwResult = TSL_ERROR_BAD_HANDLE;
  89. return dwResult;
  90. }
  91. /* TSLReInit
  92. Reinitializes handle. Functionally the same as a TSLClose followed by TSLOpen, but more
  93. efficient. Returns same handle as passed in, if handle was OK, otherwise NULL.
  94. */
  95. HANDLE WINAPI TSLReInit (HANDLE hTSL)
  96. {
  97. HRESULT hRes;
  98. HANDLE hResult = NULL;
  99. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  100. if (NULL != pITShootATL)
  101. {
  102. hRes = pITShootATL->ReInit();
  103. if (!FAILED(hRes))
  104. hResult = hTSL;
  105. }
  106. return hResult;
  107. }
  108. /* TSLLaunchKnownTS
  109. Launches to a known troubleshooting belief network and (optionally) problem node.
  110. If you know the particular troubleshooting network and problem, use this call.
  111. If setting network but not problem, pass in a NULL for szProblemNode.
  112. Also allows setting arbitrary nodes.
  113. nNode gives the number of nodes to set. pszNode, pVal are
  114. arrays (dimension nNode) of symbolic node names and corresponding values.
  115. Returns one of:
  116. TSL_OK
  117. TSL_ERROR_BAD_HANDLE
  118. TSL_ERROR_OUT_OF_MEMORY
  119. TSL_ERROR_GENERAL launch failed, call TSLStatus
  120. TSL_WARNING_GENERAL launch succeded, call TSLStatus for warnings
  121. */
  122. DWORD WINAPI TSLLaunchKnownTSA(HANDLE hTSL, const char * szNet,
  123. const char * szProblemNode, DWORD nNode, const char ** pszNode, DWORD* pVal)
  124. {
  125. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  126. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  127. if (NULL != pITShootATL)
  128. {
  129. dwResult = LaunchKnownTSA(pITShootATL, szNet, szProblemNode, nNode, pszNode, pVal);
  130. }
  131. return dwResult;
  132. }
  133. DWORD WINAPI TSLLaunchKnownTSW(HANDLE hTSL, const wchar_t * szNet,
  134. const wchar_t * szProblemNode, DWORD nNode, const wchar_t ** pszNode, DWORD* pVal)
  135. {
  136. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  137. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  138. if (NULL != pITShootATL)
  139. {
  140. dwResult = LaunchKnownTSW(pITShootATL, szNet, szProblemNode, nNode, pszNode, pVal);
  141. }
  142. return dwResult;
  143. }
  144. /* TSLLaunch
  145. Launches to a troubleshooting belief network and (optionally) problem node based
  146. on application, version, and problem.
  147. If bLaunch is true, this just queries the mapping, but does not launch.
  148. Returns one of:
  149. TSL_OK
  150. TSL_ERROR_BAD_HANDLE
  151. TSL_ERROR_OUT_OF_MEMORY
  152. TSL_ERROR_GENERAL launch/query failed, call TSLStatus
  153. TSL_WARNING_GENERAL launch/query succeeded, call TSLStatus for warnings
  154. */
  155. DWORD WINAPI TSLLaunchA(HANDLE hTSL, const char * szCallerName,
  156. const char * szCallerVersion, const char * szAppProblem, bool bLaunch)
  157. {
  158. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  159. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  160. if (NULL != pITShootATL)
  161. {
  162. _bstr_t bstrCallerName(szCallerName);
  163. _bstr_t bstrCallerVersion(szCallerVersion);
  164. _bstr_t bstrAppProblem(szAppProblem);
  165. dwResult = Launch(pITShootATL, bstrCallerName, bstrCallerVersion, bstrAppProblem, bLaunch);
  166. }
  167. return dwResult;
  168. }
  169. DWORD WINAPI TSLLaunchW(HANDLE hTSL, const wchar_t * szCallerName,
  170. const wchar_t * szCallerVersion, const wchar_t * szAppProblem, bool bLaunch)
  171. {
  172. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  173. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  174. if (NULL != pITShootATL)
  175. {
  176. _bstr_t bstrCallerName(szCallerName);
  177. _bstr_t bstrCallerVersion(szCallerVersion);
  178. _bstr_t bstrAppProblem(szAppProblem);
  179. dwResult = Launch(pITShootATL, bstrCallerName, bstrCallerVersion, bstrAppProblem, bLaunch);
  180. }
  181. return dwResult;
  182. }
  183. /* TSLLaunchDevice
  184. Launches to a troubleshooting belief network and (optionally) problem node based
  185. on application, version, Plug & Play Device ID, Device Class GUID, and problem.
  186. If bLaunch is true, this just queries the mapping, but does not launch.
  187. Returns one of:
  188. TSL_OK
  189. TSL_ERROR_BAD_HANDLE
  190. TSL_ERROR_OUT_OF_MEMORY
  191. TSL_ERROR_GENERAL launch/query failed, call TSLStatus
  192. TSL_WARNING_GENERAL launch/query succeded, call TSLStatus for warnings
  193. */
  194. DWORD WINAPI TSLLaunchDeviceA(HANDLE hTSL, const char * szCallerName,
  195. const char * szCallerVersion, const char * szPNPDeviceID,
  196. const char * szDeviceClassGUID, const char * szAppProblem, bool bLaunch)
  197. {
  198. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  199. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  200. if (NULL != pITShootATL)
  201. {
  202. _bstr_t bstrCallerName(szCallerName);
  203. _bstr_t bstrCallerVersion(szCallerVersion);
  204. _bstr_t bstrPNPDeviceID(szPNPDeviceID);
  205. _bstr_t bstrDeviceClassGUID(szDeviceClassGUID);
  206. _bstr_t bstrAppProblem(szAppProblem);
  207. dwResult = LaunchDevice(pITShootATL, bstrCallerName, bstrCallerVersion,
  208. bstrPNPDeviceID, bstrDeviceClassGUID,
  209. bstrAppProblem, bLaunch);
  210. }
  211. return dwResult;
  212. }
  213. DWORD WINAPI TSLLaunchDeviceW(HANDLE hTSL, const wchar_t * szCallerName,
  214. const wchar_t * szCallerVersion, const wchar_t * szPNPDeviceID,
  215. const wchar_t * szDeviceClassGUID, const wchar_t * szAppProblem, bool bLaunch)
  216. {
  217. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  218. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  219. if (NULL != pITShootATL)
  220. {
  221. _bstr_t bstrCallerName(szCallerName);
  222. _bstr_t bstrCallerVersion(szCallerVersion);
  223. _bstr_t bstrPNPDeviceID(szPNPDeviceID);
  224. _bstr_t bstrDeviceClassGUID(szDeviceClassGUID);
  225. _bstr_t bstrAppProblem(szAppProblem);
  226. dwResult = LaunchDevice(pITShootATL, bstrCallerName, bstrCallerVersion,
  227. bstrPNPDeviceID, bstrDeviceClassGUID,
  228. bstrAppProblem, bLaunch);
  229. }
  230. return dwResult;
  231. }
  232. /* Preferences ----------------------------------- */
  233. /* TSLPreferOnline
  234. Specify a preference for or against online debugger.
  235. Returns one of:
  236. TSL_OK
  237. TSL_ERROR_BAD_HANDLE
  238. TSL_ERROR_OUT_OF_MEMORY
  239. */
  240. DWORD WINAPI TSLPreferOnline(HANDLE hTSL, BOOL bPreferOnline)
  241. {
  242. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  243. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  244. if (NULL != pITShootATL)
  245. {
  246. dwResult = PreferOnline(pITShootATL, bPreferOnline);
  247. }
  248. return dwResult;
  249. }
  250. /* TSLLanguage
  251. Specify language, using Unicode-style 3-letter language ID. This overrides the system
  252. default.
  253. Returns one of:
  254. TSL_OK
  255. TSL_ERROR_BAD_HANDLE
  256. TSL_ERROR_OUT_OF_MEMORY
  257. Cannot return TSL_WARNING_LANGUAGE, because we will not know this till we try combining
  258. language and troubleshooting network.
  259. */
  260. DWORD WINAPI TSLLanguageA(HANDLE hTSL, const char * szLanguage)
  261. {
  262. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  263. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  264. if (NULL != pITShootATL)
  265. {
  266. dwResult = TSL_OK;
  267. }
  268. return dwResult;
  269. }
  270. DWORD WINAPI TSLLanguageW(HANDLE hTSL, const wchar_t * szLanguage)
  271. {
  272. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  273. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  274. if (NULL != pITShootATL)
  275. {
  276. dwResult = TSL_OK;
  277. }
  278. return dwResult;
  279. }
  280. /* Sniffing ---------------------------- */
  281. /* TSLMachineID
  282. Necessary to support sniffing on a remote machine.
  283. Returns one of:
  284. TSL_OK
  285. TSL_ERROR_BAD_HANDLE
  286. TSL_ERROR_OUT_OF_MEMORY
  287. TSL_ERROR_ILLFORMED_MACHINE_ID
  288. TSL_ERROR_BAD_MACHINE_ID
  289. */
  290. DWORD WINAPI TSLMachineIDA(HANDLE hTSL, const char* szMachineID)
  291. {
  292. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  293. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  294. if (NULL != pITShootATL)
  295. {
  296. _bstr_t bstrMachineID(szMachineID);
  297. dwResult = MachineID(pITShootATL, bstrMachineID);
  298. }
  299. return dwResult;
  300. }
  301. DWORD WINAPI TSLMachineIDW(HANDLE hTSL, const wchar_t* szMachineID)
  302. {
  303. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  304. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  305. if (NULL != pITShootATL)
  306. {
  307. _bstr_t bstrMachineID(szMachineID);
  308. dwResult = MachineID(pITShootATL, bstrMachineID);
  309. }
  310. return dwResult;
  311. }
  312. /* TSLDeviceInstanceIDA
  313. Necessary to support sniffing. For example, if there are two of the same card on a
  314. machine, the Plug & Play ID is of limited use for sniffing.
  315. Returns one of:
  316. TSL_OK
  317. TSL_ERROR_BAD_HANDLE
  318. TSL_ERROR_OUT_OF_MEMORY
  319. TSL_ERROR_ILLFORMED_DEVINST_ID
  320. TSL_ERROR_BAD_DEVINST_ID
  321. */
  322. DWORD WINAPI TSLDeviceInstanceIDA(HANDLE hTSL, const char* szDeviceInstanceID)
  323. {
  324. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  325. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  326. if (NULL != pITShootATL)
  327. {
  328. _bstr_t bstrDeviceInstanceID(szDeviceInstanceID);
  329. dwResult = DeviceInstanceID(pITShootATL, bstrDeviceInstanceID);
  330. }
  331. return dwResult;
  332. }
  333. DWORD WINAPI TSLDeviceInstanceIDW(HANDLE hTSL, const wchar_t* szDeviceInstanceID)
  334. {
  335. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  336. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  337. if (NULL != pITShootATL)
  338. {
  339. _bstr_t bstrDeviceInstanceID(szDeviceInstanceID);
  340. dwResult = DeviceInstanceID(pITShootATL, bstrDeviceInstanceID);
  341. }
  342. return dwResult;
  343. }
  344. /* Status (after launch) ----------------------- */
  345. /* TSLStatus
  346. After TSLGo (or after an event flag is returned by TSLGoAsynch) can return one status.
  347. Repeated calls to this function allow any number of problems to be reported.
  348. Should be called in a loop after TSLGo (or after an event flag is returned by TSLGoAsynch),
  349. loop until it returns 0.
  350. Returns TSL_OK if all OK or if all problems are already reported. nChar indicates size of
  351. buffer szBuf in characters. 255 is recommended. if present, szBuf is used to return
  352. a detailed error message. The buffer will always return appropriate text. Typically,
  353. it is just a text appropriate to the error/warning return. In the case of
  354. TSL_WARNING_NO_NODE or TSL_WARNING_NO_STATE, this text identifies what node has the
  355. problem. However, that is relevant only if there has been a call to TSLSetNodes.
  356. */
  357. DWORD WINAPI TSLStatusA (HANDLE hTSL, DWORD nChar, char * szBuf)
  358. {
  359. HRESULT hRes;
  360. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  361. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  362. if (NULL != pITShootATL)
  363. {
  364. dwResult = TSL_OK;
  365. hRes = pITShootATL->GetStatus(&dwResult);
  366. if (TSL_SERV_FAILED(hRes))
  367. return TSL_ERROR_OBJECT_GONE;
  368. SetStatusA(dwResult, nChar, szBuf);
  369. }
  370. return dwResult;
  371. }
  372. DWORD WINAPI TSLStatusW (HANDLE hTSL, DWORD nChar, wchar_t * szBuf)
  373. {
  374. HRESULT hRes;
  375. DWORD dwResult = TSL_ERROR_BAD_HANDLE;
  376. ITShootATL *pITShootATL = (ITShootATL *) g_unkList.LookUp(hTSL);
  377. if (NULL != pITShootATL)
  378. {
  379. dwResult = TSL_OK;
  380. hRes = pITShootATL->GetStatus(&dwResult);
  381. if (TSL_SERV_FAILED(hRes))
  382. return TSL_ERROR_OBJECT_GONE;
  383. SetStatusW(dwResult, nChar, szBuf);
  384. }
  385. return dwResult;
  386. }