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.

682 lines
13 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. dllentry.c
  5. Abstract:
  6. Module's entry points.
  7. Author:
  8. Ovidiu Temereanca (ovidiut) 02-Jul-2000 Initial implementation
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. #include "hwdbp.h"
  13. //
  14. // Implementation
  15. //
  16. PCSTR
  17. pConvertMultiSzToAnsi (
  18. IN PCWSTR MultiSz
  19. )
  20. {
  21. UINT logChars;
  22. if (!MultiSz) {
  23. return NULL;
  24. }
  25. logChars = MultiSzSizeInCharsW (MultiSz);
  26. return UnicodeToDbcsN (NULL, MultiSz, logChars);
  27. }
  28. BOOL
  29. WINAPI
  30. HwdbInitializeA (
  31. IN PCSTR TempDir
  32. )
  33. {
  34. BOOL b;
  35. if (HwdbpInitialized ()) {
  36. DEBUGMSGA ((DBG_WARNING, "Module already initialized"));
  37. return TRUE;
  38. }
  39. //
  40. // don't call any logging APIs until the log module is actually initialized
  41. //
  42. b = HwdbpInitialize ();
  43. if (b) {
  44. if (TempDir) {
  45. HwdbpSetTempDir (TempDir);
  46. }
  47. DEBUGMSGA ((DBG_VERBOSE, "HwdbInitializeA(%s) succeeded", TempDir));
  48. }
  49. return b;
  50. }
  51. BOOL
  52. WINAPI
  53. HwdbInitializeW (
  54. IN PCWSTR TempDir
  55. )
  56. {
  57. BOOL b;
  58. PCSTR ansi;
  59. if (HwdbpInitialized ()) {
  60. DEBUGMSGA ((DBG_WARNING, "Module already initialized"));
  61. return TRUE;
  62. }
  63. //
  64. // don't call any logging APIs until the log module is actually initialized
  65. //
  66. b = HwdbpInitialize ();
  67. if (b) {
  68. if (TempDir) {
  69. ansi = ConvertWtoA (TempDir);
  70. HwdbpSetTempDir (ansi);
  71. } else {
  72. ansi = NULL;
  73. }
  74. DEBUGMSGA ((DBG_VERBOSE, "HwdbInitializeW(%s) succeeded", ansi));
  75. if (ansi) {
  76. FreeConvertedStr (ansi);
  77. }
  78. }
  79. return b;
  80. }
  81. VOID
  82. WINAPI
  83. HwdbTerminate (
  84. VOID
  85. )
  86. {
  87. if (!HwdbpInitialized ()) {
  88. return;
  89. }
  90. DEBUGMSGA ((DBG_VERBOSE, "HwdbTerminate(): entering (TID=%u)", GetCurrentThreadId ()));
  91. HwdbpTerminate ();
  92. }
  93. HANDLE
  94. WINAPI
  95. HwdbOpenA (
  96. IN PCSTR DatabaseFile OPTIONAL
  97. )
  98. {
  99. PHWDB p;
  100. if (!HwdbpInitialized ()) {
  101. return NULL;
  102. }
  103. DEBUGMSGA ((DBG_VERBOSE, "HwdbOpenA(%s): entering (TID=%u)", DatabaseFile, GetCurrentThreadId ()));
  104. p = HwdbpOpen (DatabaseFile);
  105. DEBUGMSGA ((DBG_VERBOSE, "HwdbOpenA: leaving (p=%p, rc=%u)", p, GetLastError ()));
  106. return (HANDLE)p;
  107. }
  108. HANDLE
  109. WINAPI
  110. HwdbOpenW (
  111. IN PCWSTR DatabaseFile OPTIONAL
  112. )
  113. {
  114. PHWDB p;
  115. PCSTR ansi;
  116. if (!HwdbpInitialized ()) {
  117. return NULL;
  118. }
  119. if (DatabaseFile) {
  120. ansi = ConvertWtoA (DatabaseFile);
  121. } else {
  122. ansi = NULL;
  123. }
  124. DEBUGMSGA ((DBG_VERBOSE, "HwdbOpenW(%s): entering (TID=%u)", ansi, GetCurrentThreadId ()));
  125. p = HwdbpOpen (ansi);
  126. DEBUGMSGA ((DBG_VERBOSE, "HwdbOpenW: leaving (p=%p, rc=%u)", p, GetLastError ()));
  127. if (ansi) {
  128. FreeConvertedStr (ansi);
  129. }
  130. return (HANDLE)p;
  131. }
  132. VOID
  133. WINAPI
  134. HwdbClose (
  135. IN HANDLE Hwdb
  136. )
  137. {
  138. if (!HwdbpInitialized ()) {
  139. return;
  140. }
  141. DEBUGMSGA ((DBG_VERBOSE, "HwdbClose(%p): entering (TID=%u)", Hwdb, GetCurrentThreadId ()));
  142. HwdbpClose ((PHWDB)Hwdb);
  143. DEBUGMSGA ((DBG_VERBOSE, "HwdbClose: leaving (rc=%u)", GetLastError ()));
  144. }
  145. BOOL
  146. WINAPI
  147. HwdbAppendInfsA (
  148. IN HANDLE Hwdb,
  149. IN PCSTR SourceDirectory,
  150. IN HWDBAPPENDINFSCALLBACKA Callback, OPTIONAL
  151. IN PVOID CallbackContext OPTIONAL
  152. )
  153. {
  154. BOOL b;
  155. if (!HwdbpInitialized ()) {
  156. return FALSE;
  157. }
  158. DEBUGMSGA ((
  159. DBG_VERBOSE,
  160. "HwdbAppendInfsA(%p,%s): entering (TID=%u)",
  161. Hwdb,
  162. SourceDirectory,
  163. GetCurrentThreadId ()
  164. ));
  165. b = HwdbpAppendInfs ((PHWDB)Hwdb, SourceDirectory, Callback, CallbackContext, FALSE);
  166. DEBUGMSGA ((DBG_VERBOSE, "HwdbAppendInfsA: leaving (b=%u,rc=%u)", b, GetLastError ()));
  167. return b;
  168. }
  169. BOOL
  170. WINAPI
  171. HwdbAppendInfsW (
  172. IN HANDLE Hwdb,
  173. IN PCWSTR SourceDirectory,
  174. IN HWDBAPPENDINFSCALLBACKW Callback, OPTIONAL
  175. IN PVOID CallbackContext OPTIONAL
  176. )
  177. {
  178. BOOL b;
  179. PCSTR ansi;
  180. if (!HwdbpInitialized ()) {
  181. return FALSE;
  182. }
  183. MYASSERT (SourceDirectory);
  184. ansi = ConvertWtoA (SourceDirectory);
  185. DEBUGMSGA ((
  186. DBG_VERBOSE,
  187. "HwdbAppendInfsW(%p,%s): entering (TID=%u)",
  188. Hwdb,
  189. ansi,
  190. GetCurrentThreadId ()
  191. ));
  192. b = HwdbpAppendInfs ((PHWDB)Hwdb, ansi, (HWDBAPPENDINFSCALLBACKA)Callback, CallbackContext, TRUE);
  193. DEBUGMSGA ((DBG_VERBOSE, "HwdbAppendInfsW: leaving (b=%u,rc=%u)", b, GetLastError ()));
  194. FreeConvertedStr (ansi);
  195. return b;
  196. }
  197. BOOL
  198. WINAPI
  199. HwdbAppendDatabase (
  200. IN HANDLE HwdbTarget,
  201. IN HANDLE HwdbSource
  202. )
  203. {
  204. BOOL b;
  205. if (!HwdbpInitialized ()) {
  206. return FALSE;
  207. }
  208. DEBUGMSGA ((
  209. DBG_VERBOSE,
  210. "HwdbAppendDatabase(%p,%p): entering (TID=%u)",
  211. HwdbTarget,
  212. HwdbSource
  213. ));
  214. b = HwdbpAppendDatabase ((PHWDB)HwdbTarget, (PHWDB)HwdbSource);
  215. DEBUGMSGA ((DBG_VERBOSE, "HwdbAppendDatabase: leaving (b=%u,rc=%u)", b, GetLastError ()));
  216. return b;
  217. }
  218. BOOL
  219. WINAPI
  220. HwdbFlushA (
  221. IN HANDLE Hwdb,
  222. IN PCSTR OutputFile
  223. )
  224. {
  225. BOOL b;
  226. if (!HwdbpInitialized ()) {
  227. return FALSE;
  228. }
  229. DEBUGMSGA ((
  230. DBG_VERBOSE,
  231. "HwdbFlushA(%p,%s): entering (TID=%u)",
  232. Hwdb,
  233. OutputFile,
  234. GetCurrentThreadId ()
  235. ));
  236. b = HwdbpFlush ((PHWDB)Hwdb, OutputFile);
  237. DEBUGMSGA ((DBG_VERBOSE, "HwdbFlushA: leaving (b=%u,rc=%u)", b, GetLastError ()));
  238. return b;
  239. }
  240. BOOL
  241. WINAPI
  242. HwdbFlushW (
  243. IN HANDLE Hwdb,
  244. IN PCWSTR OutputFile
  245. )
  246. {
  247. BOOL b;
  248. PCSTR ansi;
  249. if (!HwdbpInitialized ()) {
  250. return FALSE;
  251. }
  252. MYASSERT (OutputFile);
  253. ansi = ConvertWtoA (OutputFile);
  254. DEBUGMSGA ((
  255. DBG_VERBOSE,
  256. "HwdbFlushW(%p,%s): entering (TID=%u)",
  257. Hwdb,
  258. ansi,
  259. GetCurrentThreadId ()
  260. ));
  261. b = HwdbpFlush ((PHWDB)Hwdb, ansi);
  262. DEBUGMSGA ((DBG_VERBOSE, "HwdbFlushW: leaving (b=%u,rc=%u)", b, GetLastError ()));
  263. FreeConvertedStr (ansi);
  264. return b;
  265. }
  266. BOOL
  267. WINAPI
  268. HwdbHasDriverA (
  269. IN HANDLE Hwdb,
  270. IN PCSTR PnpId,
  271. OUT PBOOL Unsupported
  272. )
  273. {
  274. BOOL b;
  275. if (!HwdbpInitialized ()) {
  276. return FALSE;
  277. }
  278. DEBUGMSGA ((
  279. DBG_VERBOSE,
  280. "HwdbHasDriverA(%p,%s,%p): entering (TID=%u)",
  281. Hwdb,
  282. PnpId,
  283. Unsupported,
  284. GetCurrentThreadId ()
  285. ));
  286. b = HwdbpHasDriver ((PHWDB)Hwdb, PnpId, Unsupported);
  287. DEBUGMSGA ((DBG_VERBOSE, "HwdbHasDriverA: leaving (b=%u,rc=%u)", b, GetLastError ()));
  288. return b;
  289. }
  290. BOOL
  291. WINAPI
  292. HwdbHasDriverW (
  293. IN HANDLE Hwdb,
  294. IN PCWSTR PnpId,
  295. OUT PBOOL Unsupported
  296. )
  297. {
  298. BOOL b;
  299. PCSTR ansi;
  300. if (!HwdbpInitialized ()) {
  301. return FALSE;
  302. }
  303. MYASSERT (PnpId);
  304. ansi = ConvertWtoA (PnpId);
  305. DEBUGMSGA ((
  306. DBG_VERBOSE,
  307. "HwdbHasDriverW(%p,%s,%p): entering (TID=%u)",
  308. Hwdb,
  309. ansi,
  310. Unsupported,
  311. GetCurrentThreadId ()
  312. ));
  313. b = HwdbpHasDriver ((PHWDB)Hwdb, ansi, Unsupported);
  314. DEBUGMSGA ((DBG_VERBOSE, "HwdbHasDriverW: leaving (b=%u,rc=%u)", b, GetLastError ()));
  315. FreeConvertedStr (ansi);
  316. return b;
  317. }
  318. BOOL
  319. WINAPI
  320. HwdbHasAnyDriverA (
  321. IN HANDLE Hwdb,
  322. IN PCSTR PnpIds,
  323. OUT PBOOL Unsupported
  324. )
  325. {
  326. BOOL b;
  327. if (!HwdbpInitialized ()) {
  328. return FALSE;
  329. }
  330. DEBUGMSGA ((
  331. DBG_VERBOSE,
  332. "HwdbHasAnyDriverA(%p,%s,%p): entering (TID=%u)",
  333. Hwdb,
  334. PnpIds,
  335. Unsupported,
  336. GetCurrentThreadId ()
  337. ));
  338. b = HwdbpHasAnyDriver ((PHWDB)Hwdb, PnpIds, Unsupported);
  339. DEBUGMSGA ((DBG_VERBOSE, "HwdbHasAnyDriverA: leaving (b=%u,rc=%u)", b, GetLastError ()));
  340. return b;
  341. }
  342. BOOL
  343. WINAPI
  344. HwdbHasAnyDriverW (
  345. IN HANDLE Hwdb,
  346. IN PCWSTR PnpIds,
  347. OUT PBOOL Unsupported
  348. )
  349. {
  350. BOOL b;
  351. PCSTR ansi;
  352. if (!HwdbpInitialized ()) {
  353. return FALSE;
  354. }
  355. ansi = pConvertMultiSzToAnsi (PnpIds);
  356. DEBUGMSGA ((
  357. DBG_VERBOSE,
  358. "HwdbHasAnyDriverW(%p,%s,%p): entering (TID=%u)",
  359. Hwdb,
  360. ansi,
  361. Unsupported,
  362. GetCurrentThreadId ()
  363. ));
  364. b = HwdbpHasAnyDriver ((PHWDB)Hwdb, ansi, Unsupported);
  365. DEBUGMSGA ((DBG_VERBOSE, "HwdbHasAnyDriverW: leaving (b=%u,rc=%u)", b, GetLastError ()));
  366. FreeConvertedStr (ansi);
  367. return b;
  368. }
  369. #if 0
  370. BOOL
  371. HwdbEnumeratePnpIdA (
  372. IN HANDLE Hwdb,
  373. IN PHWDBENUM_CALLBACKA EnumCallback,
  374. IN PVOID UserContext
  375. )
  376. {
  377. BOOL b;
  378. if (!HwdbpInitialized ()) {
  379. return FALSE;
  380. }
  381. DEBUGMSGA ((
  382. DBG_VERBOSE,
  383. "HwdbEnumeratePnpIdA: entering (TID=%u)",
  384. GetCurrentThreadId ()
  385. ));
  386. b = HwdbpEnumeratePnpIdA ((PHWDB)Hwdb, EnumCallback, UserContext);
  387. DEBUGMSGA ((DBG_VERBOSE, "HwdbEnumeratePnpIdA: leaving (b=%u,rc=%u)", b, GetLastError ()));
  388. return b;
  389. }
  390. BOOL
  391. HwdbEnumeratePnpIdW (
  392. IN HANDLE Hwdb,
  393. IN PHWDBENUM_CALLBACKW EnumCallback,
  394. IN PVOID UserContext
  395. )
  396. {
  397. BOOL b;
  398. if (!HwdbpInitialized ()) {
  399. return FALSE;
  400. }
  401. DEBUGMSGA ((
  402. DBG_VERBOSE,
  403. "HwdbEnumeratePnpIdW: entering (TID=%u)",
  404. GetCurrentThreadId ()
  405. ));
  406. b = HwdbpEnumeratePnpIdW ((PHWDB)Hwdb, EnumCallback, UserContext);
  407. DEBUGMSGA ((DBG_VERBOSE, "HwdbEnumeratePnpIdW: leaving (b=%u,rc=%u)", b, GetLastError ()));
  408. return b;
  409. }
  410. #endif
  411. BOOL
  412. HwdbEnumFirstInfA (
  413. OUT PHWDBINF_ENUMA EnumPtr,
  414. IN PCSTR DatabaseFile
  415. )
  416. {
  417. BOOL b;
  418. if (!HwdbpInitialized ()) {
  419. return FALSE;
  420. }
  421. DEBUGMSGA ((
  422. DBG_VERBOSE,
  423. "HwdbEnumFirstInfA(%s): entering (TID=%u)",
  424. DatabaseFile,
  425. GetCurrentThreadId ()
  426. ));
  427. b = HwdbpEnumFirstInfA (EnumPtr, DatabaseFile);
  428. DEBUGMSGA ((DBG_VERBOSE, "HwdbEnumFirstInfA(%s): leaving (b=%u,rc=%u)", DatabaseFile, b, GetLastError ()));
  429. return b;
  430. }
  431. BOOL
  432. HwdbEnumFirstInfW (
  433. OUT PHWDBINF_ENUMW EnumPtr,
  434. IN PCWSTR DatabaseFile
  435. )
  436. {
  437. BOOL b;
  438. PCSTR ansi;
  439. if (!HwdbpInitialized ()) {
  440. return FALSE;
  441. }
  442. MYASSERT (DatabaseFile);
  443. ansi = ConvertWtoA (DatabaseFile);
  444. DEBUGMSGA ((
  445. DBG_VERBOSE,
  446. "HwdbEnumFirstInfW: entering (TID=%u)",
  447. GetCurrentThreadId ()
  448. ));
  449. b = HwdbpEnumFirstInfW (EnumPtr, ansi);
  450. DEBUGMSGA ((DBG_VERBOSE, "HwdbEnumFirstInfW(%s): leaving (b=%u,rc=%u)", ansi, b, GetLastError ()));
  451. FreeConvertedStr (ansi);
  452. return b;
  453. }
  454. BOOL
  455. HwdbEnumNextInfA (
  456. IN OUT PHWDBINF_ENUMA EnumPtr
  457. )
  458. {
  459. BOOL b;
  460. if (!HwdbpInitialized ()) {
  461. return FALSE;
  462. }
  463. DEBUGMSGA ((
  464. DBG_VERBOSE,
  465. "HwdbEnumNextInfA: entering (TID=%u)",
  466. GetCurrentThreadId ()
  467. ));
  468. b = HwdbpEnumNextInfA (EnumPtr);
  469. DEBUGMSGA ((DBG_VERBOSE, "HwdbEnumNextInfA: leaving (b=%u,rc=%u)", b, GetLastError ()));
  470. return b;
  471. }
  472. BOOL
  473. HwdbEnumNextInfW (
  474. IN OUT PHWDBINF_ENUMW EnumPtr
  475. )
  476. {
  477. BOOL b;
  478. if (!HwdbpInitialized ()) {
  479. return FALSE;
  480. }
  481. DEBUGMSGA ((
  482. DBG_VERBOSE,
  483. "HwdbEnumNextInfW: entering (TID=%u)",
  484. GetCurrentThreadId ()
  485. ));
  486. b = HwdbpEnumNextInfW (EnumPtr);
  487. DEBUGMSGA ((DBG_VERBOSE, "HwdbEnumNextInfW: leaving (b=%u,rc=%u)", b, GetLastError ()));
  488. return b;
  489. }
  490. VOID
  491. HwdbAbortEnumInfA (
  492. IN OUT PHWDBINF_ENUMA EnumPtr
  493. )
  494. {
  495. if (!HwdbpInitialized ()) {
  496. return;
  497. }
  498. DEBUGMSGA ((DBG_VERBOSE, "HwdbAbortEnumInfA: entering"));
  499. HwdbpAbortEnumInfA (EnumPtr);
  500. DEBUGMSGA ((DBG_VERBOSE, "HwdbAbortEnumInfA: leaving"));
  501. }
  502. VOID
  503. HwdbAbortEnumInfW (
  504. IN OUT PHWDBINF_ENUMW EnumPtr
  505. )
  506. {
  507. if (!HwdbpInitialized ()) {
  508. return;
  509. }
  510. DEBUGMSGA ((DBG_VERBOSE, "HwdbAbortEnumInfW: entering"));
  511. HwdbpAbortEnumInfW (EnumPtr);
  512. DEBUGMSGA ((DBG_VERBOSE, "HwdbAbortEnumInfW: leaving"));
  513. }