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.

115 lines
2.3 KiB

  1. //
  2. // dllmain.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "candui.h"
  7. #include "osver.h"
  8. DECLARE_OSVER();
  9. #ifdef DEBUG
  10. //
  11. // for prvlib.lib
  12. //
  13. DWORD g_dwThreadDllMain = 0;
  14. #endif
  15. //+---------------------------------------------------------------------------
  16. //
  17. // ProcessAttach
  18. //
  19. //----------------------------------------------------------------------------
  20. BOOL ProcessAttach(HINSTANCE hInstance)
  21. {
  22. CcshellGetDebugFlags();
  23. Dbg_MemInit(TEXT("MSUIMUI"), NULL);
  24. if (!g_cs.Init())
  25. return FALSE;
  26. g_hInst = hInstance;
  27. InitOSVer();
  28. // shared data
  29. InitCandUISecurityAttributes();
  30. g_ShareMem.Initialize();
  31. g_ShareMem.Open();
  32. // initialize messages
  33. g_msgHookedMouse = RegisterWindowMessage( SZMSG_HOOKEDMOUSE );
  34. g_msgHookedKey = RegisterWindowMessage( SZMSG_HOOKEDKEY );
  35. return TRUE;
  36. }
  37. //+---------------------------------------------------------------------------
  38. //
  39. // ProcessDetach
  40. //
  41. //----------------------------------------------------------------------------
  42. void ProcessDetach(HINSTANCE hInstance)
  43. {
  44. g_ShareMem.Close();
  45. DoneCandUISecurityAttributes();
  46. g_cs.Delete();
  47. Dbg_MemUninit();
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // DllMain
  52. //
  53. //----------------------------------------------------------------------------
  54. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID pvReserved)
  55. {
  56. #ifdef DEBUG
  57. g_dwThreadDllMain = GetCurrentThreadId();
  58. #endif
  59. switch (dwReason) {
  60. case DLL_PROCESS_ATTACH: {
  61. //
  62. // Now real DllEntry point is _DllMainCRTStartup.
  63. // _DllMainCRTStartup does not call our DllMain(DLL_PROCESS_DETACH)
  64. // if our DllMain(DLL_PROCESS_ATTACH) fails.
  65. // So we have to clean this up.
  66. //
  67. if (!ProcessAttach(hInstance))
  68. {
  69. ProcessDetach(hInstance);
  70. return FALSE;
  71. }
  72. break;
  73. }
  74. case DLL_THREAD_ATTACH: {
  75. break;
  76. }
  77. case DLL_THREAD_DETACH: {
  78. break;
  79. }
  80. case DLL_PROCESS_DETACH: {
  81. ProcessDetach(hInstance);
  82. break;
  83. }
  84. }
  85. #ifdef DEBUG
  86. g_dwThreadDllMain = 0;
  87. #endif
  88. return TRUE;
  89. }