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.

161 lines
3.1 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation
  3. Module Name:
  4. dllinit.cpp
  5. Abstract:
  6. This module implements the dll related function
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. #include "devmgr.h"
  12. #include "factory.h"
  13. LPCTSTR DEVMGR_DEVICEID_SWITCH = TEXT("DMDeviceId");
  14. LPCTSTR DEVMGR_MACHINENAME_SWITCH = TEXT("DMMachineName");
  15. LPCTSTR DEVMGR_COMMAND_SWITCH = TEXT("DMCommand");
  16. //
  17. // DLL main entry point
  18. // INPUT:
  19. // HINSTANCE hInstance -- module instance handle
  20. // DWORD dwReason -- the reason why we are called.
  21. // LPVOID lpReserved -- no used here
  22. BOOL
  23. DllMain(
  24. HINSTANCE hInstance,
  25. DWORD dwReason,
  26. LPVOID lpReserved
  27. )
  28. {
  29. UNREFERENCED_PARAMETER(lpReserved);
  30. switch (dwReason)
  31. {
  32. case DLL_PROCESS_ATTACH:
  33. // we do not need thread attach/detach calls
  34. DisableThreadLibraryCalls(hInstance);
  35. if (!SHFusionInitializeFromModule(hInstance)) {
  36. return FALSE;
  37. }
  38. // do must be done
  39. InitCommonControls();
  40. // initiailze our global stuff
  41. InitGlobals(hInstance);
  42. break;
  43. case DLL_PROCESS_DETACH:
  44. // do the clean up here.....
  45. SHFusionUninitialize();
  46. break;
  47. }
  48. return(TRUE);
  49. }
  50. BOOL InitGlobals(
  51. HINSTANCE hInstance
  52. )
  53. {
  54. g_hInstance = hInstance;
  55. // preload memory allocation error message
  56. TCHAR tszTemp[256];
  57. ::LoadString(hInstance, IDS_ERROR_NOMEMORY, tszTemp, ARRAYLEN(tszTemp));
  58. g_MemoryException.SetMessage(tszTemp);
  59. ::LoadString(hInstance, IDS_NAME_DEVMGR, tszTemp, ARRAYLEN(tszTemp));
  60. g_MemoryException.SetCaption(tszTemp);
  61. try
  62. {
  63. //preload strings
  64. g_strDevMgr.LoadString(hInstance, IDS_NAME_DEVMGR);
  65. // parse the command line and establish machine name and etc
  66. CDMCommandLine CmdLine;
  67. CmdLine.ParseCommandLine(GetCommandLine());
  68. g_strStartupMachineName = CmdLine.GetMachineName();
  69. g_strStartupDeviceId = CmdLine.GetDeviceId();
  70. g_strStartupCommand = CmdLine.GetCommand();
  71. }
  72. catch (CMemoryException* e)
  73. {
  74. e->ReportError();
  75. e->Delete();
  76. return FALSE;
  77. }
  78. return TRUE;
  79. }
  80. //
  81. // Overloaded allocation operators
  82. //
  83. void * __cdecl operator new(
  84. size_t size)
  85. {
  86. return ((void *)LocalAlloc(LPTR, size));
  87. }
  88. void __cdecl operator delete(
  89. void *ptr)
  90. {
  91. LocalFree(ptr);
  92. }
  93. __cdecl _purecall(void)
  94. {
  95. return (0);
  96. }
  97. //
  98. // Standard APIs for a OLE server. They are all routed to CClassFactory
  99. // support functions
  100. //
  101. //
  102. STDAPI
  103. DllRegisterServer()
  104. {
  105. return CClassFactory::RegisterAll();
  106. }
  107. STDAPI
  108. DllUnregisterServer()
  109. {
  110. return CClassFactory::UnregisterAll();
  111. }
  112. STDAPI
  113. DllCanUnloadNow()
  114. {
  115. return CClassFactory::CanUnloadNow();
  116. }
  117. STDAPI
  118. DllGetClassObject(
  119. REFCLSID rclsid,
  120. REFIID riid,
  121. void** ppv
  122. )
  123. {
  124. return CClassFactory::GetClassObject(rclsid, riid, ppv);
  125. }