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.

154 lines
4.2 KiB

  1. // dsctl.cpp : Implementation of DLL Exports.
  2. // To fully complete this project follow these steps
  3. // You will need the new MIDL compiler to build this project. Additionally,
  4. // if you are building the proxy stub DLL, you will need new headers and libs.
  5. // 1) Add a custom build step to dsctl.idl
  6. // You can select all of the .IDL files by holding Ctrl and clicking on
  7. // each of them.
  8. //
  9. // Description
  10. // Running MIDL
  11. // Build Command(s)
  12. // midl dsctl.idl
  13. // Outputs
  14. // dsctl.tlb
  15. // dsctl.h
  16. // dsctl_i.c
  17. // dsctl_p.c
  18. // dlldata.c
  19. //
  20. // NOTE: You must use the MIDL compiler from NT 4.0,
  21. // preferably 3.00.15 or greater
  22. // 2) Add a custom build step to the project to register the DLL
  23. // For this, you can select all projects at once
  24. // Description
  25. // Registering OLE Server...
  26. // Build Command(s)
  27. // regsvr32 /s /c "$(TargetPath)"
  28. // echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
  29. // Outputs
  30. // $(OutDir)\regsvr32.trg
  31. // 3) To add UNICODE support, follow these steps
  32. // Select Build|Configurations...
  33. // Press Add...
  34. // Change the configuration name to Unicode Release
  35. // Change the "Copy Settings From" combo to dsctl - Win32 Release
  36. // Press OK
  37. // Press Add...
  38. // Change the configuration name to Unicode Debug
  39. // Change the "Copy Settings From" combo to dsctl - Win32 Debug
  40. // Press OK
  41. // Press "Close"
  42. // Select Build|Settings...
  43. // Select the two UNICODE projects and press the C++ tab.
  44. // Select the "General" category
  45. // Add _UNICODE to the Preprocessor definitions
  46. // Select the Unicode Debug project
  47. // Press the "General" tab
  48. // Specify DebugU for the intermediate and output directories
  49. // Select the Unicode Release project
  50. // Press the "General" tab
  51. // Specify ReleaseU for the intermediate and output directories
  52. // 4) Proxy stub DLL
  53. // To merge the proxy/stub code into the object DLL, add the file
  54. // dlldatax.c to the project. Make sure precompiled headers
  55. // is turned off for this file, and add _MERGE_PROXYSTUB to the
  56. // defines for the project.
  57. // To build a separate proxy/stub DLL,
  58. // run nmake -f ps.mak in the project directory.
  59. #include "stdafx.h"
  60. #include "resource.h"
  61. #include "initguid.h"
  62. #include "dsctl.h"
  63. #include "DsctlObj.h"
  64. #include "dlldatax.h"
  65. #define IID_DEFINED
  66. #include "dsctl_i.c"
  67. CComModule _Module;
  68. BEGIN_OBJECT_MAP(ObjectMap)
  69. OBJECT_ENTRY(CLSID_Dsctl, CDsctlObject)
  70. END_OBJECT_MAP()
  71. /////////////////////////////////////////////////////////////////////////////
  72. // DLL Entry Point
  73. extern "C"
  74. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  75. {
  76. #ifdef _MERGE_PROXYSTUB
  77. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  78. return FALSE;
  79. #endif
  80. if (dwReason == DLL_PROCESS_ATTACH)
  81. {
  82. _Module.Init(ObjectMap, hInstance);
  83. DisableThreadLibraryCalls(hInstance);
  84. }
  85. else if (dwReason == DLL_PROCESS_DETACH)
  86. _Module.Term();
  87. return TRUE; // ok
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // Used to determine whether the DLL can be unloaded by OLE
  91. STDAPI DllCanUnloadNow(void)
  92. {
  93. #ifdef _MERGE_PROXYSTUB
  94. if (PrxDllCanUnloadNow() != S_OK)
  95. return S_FALSE;
  96. #endif
  97. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. // Returns a class factory to create an object of the requested type
  101. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  102. {
  103. #ifdef _MERGE_PROXYSTUB
  104. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  105. return S_OK;
  106. #endif
  107. return _Module.GetClassObject(rclsid, riid, ppv);
  108. }
  109. /////////////////////////////////////////////////////////////////////////////
  110. // DllRegisterServer - Adds entries to the system registry
  111. STDAPI DllRegisterServer(void)
  112. {
  113. HRESULT hRes = S_OK;
  114. #ifdef _MERGE_PROXYSTUB
  115. hRes = PrxDllRegisterServer();
  116. if (FAILED(hRes))
  117. return hRes;
  118. #endif
  119. // registers object, typelib and all interfaces in typelib
  120. hRes = _Module.RegisterServer(TRUE);
  121. return hRes;
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // DllUnregisterServer - Adds entries to the system registry
  125. STDAPI DllUnregisterServer(void)
  126. {
  127. HRESULT hRes = S_OK;
  128. _Module.UnregisterServer();
  129. #ifdef _MERGE_PROXYSTUB
  130. hRes = PrxDllUnregisterServer();
  131. #endif
  132. return hRes;
  133. }