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
3.3 KiB

  1. //
  2. // sainstallcom.cpp : Implementation of DLL Exports.
  3. //
  4. // Note: Proxy/Stub Information
  5. // To merge the proxy/stub code into the object DLL, add the file
  6. // dlldatax.c to the project. Make sure precompiled headers
  7. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  8. // defines for the project.
  9. //
  10. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  11. // need to remove the following define from dlldatax.c
  12. // #define _WIN32_WINNT 0x0400
  13. //
  14. // Further, if you are running MIDL without /Oicf switch, you also
  15. // need to remove the following define from dlldatax.c.
  16. // #define USE_STUBLESS_PROXY
  17. //
  18. // Modify the custom build rule for sainstallcom.idl by adding the following
  19. // files to the Outputs.
  20. // sainstallcom_p.c
  21. // dlldata.c
  22. // To build a separate proxy/stub DLL,
  23. // run nmake -f sainstallcomps.mk in the project directory.
  24. #include "stdafx.h"
  25. #include "resource.h"
  26. #include <initguid.h>
  27. #include "sainstallcom.h"
  28. #include "dlldatax.h"
  29. #include "sainstallcom_i.c"
  30. #include "SaInstall.h"
  31. #ifdef _MERGE_PROXYSTUB
  32. extern "C" HINSTANCE hProxyDll;
  33. #endif
  34. CComModule _Module;
  35. BEGIN_OBJECT_MAP(ObjectMap)
  36. OBJECT_ENTRY(CLSID_SaInstall, SaInstall)
  37. END_OBJECT_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // DLL Entry Point
  40. extern "C"
  41. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  42. {
  43. lpReserved;
  44. #ifdef _MERGE_PROXYSTUB
  45. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  46. return FALSE;
  47. #endif
  48. if (dwReason == DLL_PROCESS_ATTACH)
  49. {
  50. _Module.Init(ObjectMap, hInstance, &LIBID_SAINSTALLCOMLib);
  51. DisableThreadLibraryCalls(hInstance);
  52. }
  53. else if (dwReason == DLL_PROCESS_DETACH)
  54. _Module.Term();
  55. return TRUE; // ok
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // Used to determine whether the DLL can be unloaded by OLE
  59. STDAPI DllCanUnloadNow(void)
  60. {
  61. #ifdef _MERGE_PROXYSTUB
  62. if (PrxDllCanUnloadNow() != S_OK)
  63. return S_FALSE;
  64. #endif
  65. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // Returns a class factory to create an object of the requested type
  69. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  70. {
  71. #ifdef _MERGE_PROXYSTUB
  72. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  73. return S_OK;
  74. #endif
  75. return _Module.GetClassObject(rclsid, riid, ppv);
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // DllRegisterServer - Adds entries to the system registry
  79. STDAPI DllRegisterServer(void)
  80. {
  81. #ifdef _MERGE_PROXYSTUB
  82. HRESULT hRes = PrxDllRegisterServer();
  83. if (FAILED(hRes))
  84. return hRes;
  85. #endif
  86. // registers object, typelib and all interfaces in typelib
  87. HRESULT hr = _Module.RegisterServer(TRUE);
  88. return hr;
  89. }
  90. /////////////////////////////////////////////////////////////////////////////
  91. // DllUnregisterServer - Removes entries from the system registry
  92. STDAPI DllUnregisterServer(void)
  93. {
  94. #ifdef _MERGE_PROXYSTUB
  95. PrxDllUnregisterServer();
  96. #endif
  97. return _Module.UnregisterServer(TRUE);
  98. }