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.

157 lines
4.6 KiB

  1. // Mdsp.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 Mdsp.idl by adding the following
  17. // files to the Outputs.
  18. // Mdsp_p.c
  19. // dlldata.c
  20. // To build a separate proxy/stub DLL,
  21. // run nmake -f Mdspps.mk in the project directory.
  22. #include "stdafx.h"
  23. #include "resource.h"
  24. #include "initguid.h"
  25. #include "MsPMSP.h"
  26. #include "dlldatax.h"
  27. #include "MsPMSP_i.c"
  28. #include "MDServiceProvider.h"
  29. //#include "MDSPEnumDevice.h"
  30. //#include "MDSPDevice.h"
  31. //#include "MDSPEnumStorage.h"
  32. //#include "MDSPStorage.h"
  33. //#include "MDSPStorageGlobals.h"
  34. #include "MdspDefs.h"
  35. #include "scserver.h"
  36. #ifdef _MERGE_PROXYSTUB
  37. extern "C" HINSTANCE hProxyDll;
  38. #endif
  39. CComModule _Module;
  40. DWORD g_dwStartDrive;
  41. HINSTANCE g_hinstance;
  42. MDSPNOTIFYINFO g_NotifyInfo[MDSP_MAX_DEVICE_OBJ];
  43. MDSPGLOBALDEVICEINFO g_GlobalDeviceInfo[MDSP_MAX_DEVICE_OBJ];
  44. WCHAR g_wcsBackslash[2] = { (WCHAR)0x5c, NULL };
  45. CHAR g_szBackslash[2] = {(CHAR)0x5c, NULL };
  46. CComMultiThreadModel::AutoCriticalSection g_CriticalSection;
  47. CSecureChannelServer *g_pAppSCServer=NULL;
  48. BOOL g_bIsWinNT;
  49. BEGIN_OBJECT_MAP(ObjectMap)
  50. OBJECT_ENTRY(CLSID_MDServiceProvider, CMDServiceProvider)
  51. // OBJECT_ENTRY(CLSID_MDSPEnumDevice, CMDSPEnumDevice)
  52. // OBJECT_ENTRY(CLSID_MDSPDevice, CMDSPDevice)
  53. // OBJECT_ENTRY(CLSID_MDSPEnumFormatSupport, CMDSPEnumFormatSupport)
  54. // OBJECT_ENTRY(CLSID_MDSPEnumStorage, CMDSPEnumStorage)
  55. // OBJECT_ENTRY(CLSID_MDSPStorage, CMDSPStorage)
  56. // OBJECT_ENTRY(CLSID_MDSPStorageGlobals, CMDSPStorageGlobals)
  57. END_OBJECT_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // DLL Entry Point
  60. extern "C"
  61. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  62. {
  63. lpReserved;
  64. #ifdef _MERGE_PROXYSTUB
  65. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  66. return FALSE;
  67. #endif
  68. if (dwReason == DLL_PROCESS_ATTACH)
  69. {
  70. _Module.Init(ObjectMap, hInstance);
  71. DisableThreadLibraryCalls(hInstance);
  72. }
  73. else if (dwReason == DLL_PROCESS_DETACH)
  74. _Module.Term();
  75. g_hinstance = hInstance;
  76. return TRUE; // ok
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // Used to determine whether the DLL can be unloaded by OLE
  80. STDAPI DllCanUnloadNow(void)
  81. {
  82. #ifdef _MERGE_PROXYSTUB
  83. if (PrxDllCanUnloadNow() != S_OK)
  84. return S_FALSE;
  85. #endif
  86. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // Returns a class factory to create an object of the requested type
  90. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  91. {
  92. #ifdef _MERGE_PROXYSTUB
  93. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  94. return S_OK;
  95. #endif
  96. return _Module.GetClassObject(rclsid, riid, ppv);
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. // DllRegisterServer - Adds entries to the system registry
  100. STDAPI DllRegisterServer(void)
  101. {
  102. #ifdef _MERGE_PROXYSTUB
  103. HRESULT hRes = PrxDllRegisterServer();
  104. if (FAILED(hRes))
  105. return hRes;
  106. #endif
  107. char szTemp[MAX_PATH];
  108. HKEY hKey;
  109. if( !RegCreateKeyEx(HKEY_LOCAL_MACHINE, STR_MDSPREG, 0, NULL,
  110. REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &hKey, NULL) )
  111. {
  112. strcpy(szTemp, STR_MDSPPROGID);
  113. RegSetValueEx( hKey, "ProgID", 0, REG_SZ, (LPBYTE)szTemp, sizeof(szTemp));
  114. #ifdef MDSP_TEMP
  115. DWORD dwSD=1;
  116. RegSetValueEx( hKey, "StartDrive", 0, REG_DWORD, (LPBYTE)&dwSD, sizeof(DWORD));
  117. #endif
  118. RegCloseKey(hKey);
  119. // registers object, typelib and all interfaces in typelib
  120. return _Module.RegisterServer(TRUE);
  121. } else return REGDB_E_WRITEREGDB;
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // DllUnregisterServer - Removes entries from the system registry
  125. STDAPI DllUnregisterServer(void)
  126. {
  127. #ifdef _MERGE_PROXYSTUB
  128. PrxDllUnregisterServer();
  129. #endif
  130. _Module.UnregisterServer();
  131. RegDeleteKey(HKEY_LOCAL_MACHINE, STR_MDSPREG);
  132. return S_OK;
  133. }