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.

145 lines
3.8 KiB

  1. // csamsp.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To merge the proxy/stub code into the object DLL, add the file
  4. // dlldatax.c to the project. Make sure precompiled headers
  5. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  6. // defines for the project.
  7. //
  8. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  9. // need to remove the following define from dlldatax.c
  10. // #define _WIN32_WINNT 0x0400
  11. //
  12. // Further, if you are running MIDL without /Oicf switch, you also
  13. // need to remove the following define from dlldatax.c.
  14. // #define USE_STUBLESS_PROXY
  15. //
  16. // Modify the custom build rule for wavemsp.idl by adding the following
  17. // files to the Outputs.
  18. // wavemsp_p.c
  19. // dlldata.c
  20. // To build a separate proxy/stub DLL,
  21. // run nmake -f wavemspps.mk in the project directory.
  22. #include "stdafx.h"
  23. #include "resource.h"
  24. #include "initguid.h"
  25. #include "csamsp_i.c"
  26. //
  27. // For the ntbuild environment we need to include this file to get the base
  28. // class implementations.
  29. #ifdef _ATL_STATIC_REGISTRY
  30. #include <statreg.h>
  31. #include <statreg.cpp>
  32. #endif
  33. #include <atlimpl.cpp>
  34. #ifdef _MERGE_PROXYSTUB
  35. extern "C" HINSTANCE hProxyDll;
  36. #endif
  37. #ifdef DEBUG_HEAPS
  38. #include <crtdbg.h>
  39. #endif // DEBUG_HEAPS
  40. CComModule _Module;
  41. BEGIN_OBJECT_MAP(ObjectMap)
  42. OBJECT_ENTRY(CLSID_CSAMSP, CWaveMSP)
  43. END_OBJECT_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // DLL Entry Point
  46. extern "C"
  47. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  48. {
  49. lpReserved;
  50. #ifdef _MERGE_PROXYSTUB
  51. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  52. return FALSE;
  53. #endif
  54. if (dwReason == DLL_PROCESS_ATTACH)
  55. {
  56. #ifdef DEBUG_HEAPS
  57. // ZoltanS: turn on leak detection on process exit
  58. _CrtSetDbgFlag( _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF );
  59. // ZoltanS: force a memory leak
  60. char * leak = new char [ 1977 ];
  61. sprintf(leak, "csamsp.dll NORMAL leak");
  62. leak = NULL;
  63. #endif // DEBUG_HEAPS
  64. _Module.Init(ObjectMap, hInstance);
  65. DisableThreadLibraryCalls(hInstance);
  66. // Register for trace output.
  67. MSPLOGREGISTER(_T("CSA MSP"));
  68. }
  69. else if (dwReason == DLL_PROCESS_DETACH)
  70. {
  71. // Deregister for trace output.
  72. MSPLOGDEREGISTER();
  73. _Module.Term();
  74. }
  75. return TRUE; // ok
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // Used to determine whether the DLL can be unloaded by OLE
  79. STDAPI DllCanUnloadNow(void)
  80. {
  81. #ifdef _MERGE_PROXYSTUB
  82. if (PrxDllCanUnloadNow() != S_OK)
  83. return S_FALSE;
  84. #endif
  85. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. // Returns a class factory to create an object of the requested type
  89. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  90. {
  91. #ifdef _MERGE_PROXYSTUB
  92. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  93. return S_OK;
  94. #endif
  95. return _Module.GetClassObject(rclsid, riid, ppv);
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // DllRegisterServer - Adds entries to the system registry
  99. STDAPI DllRegisterServer(void)
  100. {
  101. #ifdef _MERGE_PROXYSTUB
  102. HRESULT hRes = PrxDllRegisterServer();
  103. if (FAILED(hRes))
  104. return hRes;
  105. #endif
  106. // registers object, typelib and all interfaces in typelib
  107. return _Module.RegisterServer(TRUE);
  108. }
  109. /////////////////////////////////////////////////////////////////////////////
  110. // DllUnregisterServer - Removes entries from the system registry
  111. STDAPI DllUnregisterServer(void)
  112. {
  113. #ifdef _MERGE_PROXYSTUB
  114. PrxDllUnregisterServer();
  115. #endif
  116. _Module.UnregisterServer();
  117. return S_OK;
  118. }