Windows NT 4.0 source code leak
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.

147 lines
3.2 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. This module contains the startup and termination code for the
  7. User-mode Plug-and-Play service.
  8. Author:
  9. Paula Tomlinson (paulat) 6-20-1995
  10. Environment:
  11. User mode only.
  12. Revision History:
  13. 3-Mar-1995 paulat
  14. Creation and initial implementation.
  15. --*/
  16. //
  17. // includes
  18. //
  19. #include "precomp.h"
  20. #include "umpnpdat.h"
  21. //
  22. // global data
  23. //
  24. HANDLE hInst; // Module handle
  25. HKEY ghEnumKey = NULL; // Key to HKLM\CCC\System\Enum
  26. HKEY ghServicesKey = NULL; // Key to HKLM\CCC\System\Services
  27. HKEY ghClassKey = NULL; // key to HKLM\CCC\System\Class
  28. BOOL
  29. DllMainCRTStartup(
  30. PVOID hModule,
  31. ULONG Reason,
  32. PCONTEXT pContext
  33. )
  34. /*++
  35. Routine Description:
  36. This is the standard DLL entrypoint routine, called whenever a process
  37. or thread attaches or detaches.
  38. Arguments:
  39. hModule - PVOID parameter that specifies the handle of the DLL
  40. Reason - ULONG parameter that specifies the reason this entrypoint
  41. was called (either PROCESS_ATTACH, PROCESS_DETACH,
  42. THREAD_ATTACH, or THREAD_DETACH).
  43. pContext - ???
  44. Return value:
  45. Returns true if initialization compeleted successfully, false is not.
  46. --*/
  47. {
  48. hInst = (HANDLE)hModule;
  49. DBG_UNREFERENCED_PARAMETER(pContext);
  50. switch(Reason) {
  51. case DLL_PROCESS_ATTACH:
  52. if (ghEnumKey == NULL) {
  53. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, pszRegPathEnum, 0,
  54. KEY_ALL_ACCESS, &ghEnumKey)
  55. != ERROR_SUCCESS) {
  56. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, pszRegPathEnum,
  57. 0, NULL, REG_OPTION_NON_VOLATILE,
  58. KEY_ALL_ACCESS, NULL, &ghEnumKey,
  59. NULL) != ERROR_SUCCESS) {
  60. ghEnumKey = NULL;
  61. }
  62. }
  63. }
  64. if (ghServicesKey == NULL) {
  65. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, pszRegPathServices, 0,
  66. KEY_ALL_ACCESS, &ghServicesKey)
  67. != ERROR_SUCCESS) {
  68. ghServicesKey = NULL;
  69. }
  70. }
  71. if (ghClassKey == NULL) {
  72. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, pszRegPathClass, 0,
  73. KEY_ALL_ACCESS, &ghClassKey)
  74. != ERROR_SUCCESS) {
  75. ghClassKey = NULL;
  76. }
  77. }
  78. break;
  79. case DLL_PROCESS_DETACH:
  80. if (ghEnumKey != NULL) {
  81. RegCloseKey(ghEnumKey);
  82. ghEnumKey = NULL;
  83. }
  84. if (ghServicesKey != NULL) {
  85. RegCloseKey(ghServicesKey);
  86. ghServicesKey = NULL;
  87. }
  88. if (ghClassKey != NULL) {
  89. RegCloseKey(ghClassKey);
  90. ghClassKey == NULL;
  91. }
  92. break;
  93. case DLL_THREAD_ATTACH:
  94. case DLL_THREAD_DETACH:
  95. break;
  96. }
  97. return TRUE;
  98. } // DllMainCRTStartup