Source code of Windows XP (NT5)
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.

165 lines
3.0 KiB

  1. /*++
  2. Copyright (C) 1997-1999 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. switch (dwReason)
  30. {
  31. case DLL_PROCESS_ATTACH:
  32. // we do not need thread attach/detach calls
  33. DisableThreadLibraryCalls(hInstance);
  34. SHFusionInitializeFromModule(hInstance);
  35. // do must be done
  36. InitCommonControls();
  37. INITCOMMONCONTROLSEX icce;
  38. icce.dwSize = sizeof(icce);
  39. icce.dwICC = ICC_DATE_CLASSES;
  40. InitCommonControlsEx(&icce);
  41. // initiailze our global stuff
  42. InitGlobals(hInstance);
  43. break;
  44. case DLL_PROCESS_DETACH:
  45. // do the clean up here.....
  46. SHFusionUninitialize();
  47. break;
  48. }
  49. return(TRUE);
  50. }
  51. BOOL InitGlobals(
  52. HINSTANCE hInstance
  53. )
  54. {
  55. g_hInstance = hInstance;
  56. // preload memory allocation error message
  57. TCHAR tszTemp[256];
  58. ::LoadString(hInstance, IDS_ERROR_NOMEMORY, tszTemp, ARRAYLEN(tszTemp));
  59. g_MemoryException.SetMessage(tszTemp);
  60. ::LoadString(hInstance, IDS_NAME_DEVMGR, tszTemp, ARRAYLEN(tszTemp));
  61. g_MemoryException.SetCaption(tszTemp);
  62. try
  63. {
  64. //preload strings
  65. g_strDevMgr.LoadString(hInstance, IDS_NAME_DEVMGR);
  66. // parse the command line and establish machine name and etc
  67. CDMCommandLine CmdLine;
  68. CmdLine.ParseCommandLine(GetCommandLine());
  69. g_strStartupMachineName = CmdLine.GetMachineName();
  70. g_strStartupDeviceId = CmdLine.GetDeviceId();
  71. g_strStartupCommand = CmdLine.GetCommand();
  72. }
  73. catch (CMemoryException* e)
  74. {
  75. e->ReportError();
  76. e->Delete();
  77. return FALSE;
  78. }
  79. return TRUE;
  80. }
  81. //
  82. // Overloaded allocation operators
  83. //
  84. void * __cdecl operator new(
  85. size_t size)
  86. {
  87. return ((void *)LocalAlloc(LPTR, size));
  88. }
  89. void __cdecl operator delete(
  90. void *ptr)
  91. {
  92. LocalFree(ptr);
  93. }
  94. __cdecl _purecall(void)
  95. {
  96. return (0);
  97. }
  98. //
  99. // Standard APIs for a OLE server. They are all routed to CClassFactory
  100. // support functions
  101. //
  102. //
  103. STDAPI
  104. DllRegisterServer()
  105. {
  106. return CClassFactory::RegisterAll();
  107. }
  108. STDAPI
  109. DllUnregisterServer()
  110. {
  111. return CClassFactory::UnregisterAll();
  112. }
  113. STDAPI
  114. DllCanUnloadNow()
  115. {
  116. return CClassFactory::CanUnloadNow();
  117. }
  118. STDAPI
  119. DllGetClassObject(
  120. REFCLSID rclsid,
  121. REFIID riid,
  122. void** ppv
  123. )
  124. {
  125. return CClassFactory::GetClassObject(rclsid, riid, ppv);
  126. }