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.

140 lines
4.0 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // � 1999 Microsoft Corporation. All rights reserved.
  4. //
  5. // Refer to your End User License Agreement for details on your rights/restrictions to use these sample files.
  6. //
  7. // MSHDSP.DLL is a sample WMDM Service Provider(SP) that enumerates fixed drives.
  8. // This sample shows you how to implement an SP according to the WMDM documentation.
  9. // This sample uses fixed drives on your PC to emulate portable media, and
  10. // shows the relationship between different interfaces and objects. Each hard disk
  11. // volume is enumerated as a device and directories and files are enumerated as
  12. // Storage objects under respective devices. You can copy non-SDMI compliant content
  13. // to any device that this SP enumerates. To copy an SDMI compliant content to a
  14. // device, the device must be able to report a hardware embedded serial number.
  15. // Hard disks do not have such serial numbers.
  16. //
  17. // To build this SP, you are recommended to use the MSHDSP.DSP file under Microsoft
  18. // Visual C++ 6.0 and run REGSVR32.EXE to register the resulting MSHDSP.DLL. You can
  19. // then build the sample application from the WMDMAPP directory to see how it gets
  20. // loaded by the application. However, you need to obtain a certificate from
  21. // Microsoft to actually run this SP. This certificate would be in the KEY.C file
  22. // under the INCLUDE directory for one level up.
  23. // Mdsp.cpp : Implementation of MSHDSP.DLL's DLL Exports.
  24. #include "hdspPCH.h"
  25. #include "initguid.h"
  26. #include "LyraSP_i.c"
  27. CComModule _Module;
  28. HINSTANCE g_hinstance;
  29. MDSPGLOBALDEVICEINFO g_GlobalDeviceInfo[MDSP_MAX_DEVICE_OBJ];
  30. WCHAR g_wcsBackslash[2] = { (WCHAR)0x5c, NULL };
  31. CHAR g_szBackslash[2] = { (CHAR)0x5c, NULL };
  32. CSecureChannelServer *g_pAppSCServer=NULL;
  33. CComMultiThreadModel::AutoCriticalSection g_CriticalSection;
  34. BOOL g_bIsWinNT;
  35. BEGIN_OBJECT_MAP(ObjectMap)
  36. OBJECT_ENTRY(CLSID_MDServiceProvider, CMDServiceProvider)
  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. if (dwReason == DLL_PROCESS_ATTACH)
  45. {
  46. _Module.Init(ObjectMap, hInstance);
  47. DisableThreadLibraryCalls(hInstance);
  48. }
  49. else if (dwReason == DLL_PROCESS_DETACH)
  50. _Module.Term();
  51. g_hinstance = hInstance;
  52. return TRUE; // ok
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Used to determine whether the DLL can be unloaded by OLE
  56. STDAPI DllCanUnloadNow(void)
  57. {
  58. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Returns a class factory to create an object of the requested type
  62. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  63. {
  64. return _Module.GetClassObject(rclsid, riid, ppv);
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // DllRegisterServer - Adds entries to the system registry
  68. STDAPI DllRegisterServer(void)
  69. {
  70. HKEY hKey;
  71. LONG lRet;
  72. lRet = RegCreateKeyEx(
  73. HKEY_LOCAL_MACHINE,
  74. STR_MDSPREG,
  75. 0,
  76. NULL,
  77. REG_OPTION_NON_VOLATILE,
  78. KEY_READ | KEY_WRITE,
  79. NULL,
  80. &hKey,
  81. NULL
  82. );
  83. if( ERROR_SUCCESS == lRet )
  84. {
  85. CHAR szTemp[MAX_PATH];
  86. // Register the ProgID with WMDM
  87. //
  88. strcpy( szTemp, STR_MDSPPROGID );
  89. RegSetValueEx(
  90. hKey,
  91. "ProgID",
  92. 0,
  93. REG_SZ,
  94. (LPBYTE)szTemp,
  95. lstrlen( szTemp ) + 1
  96. );
  97. RegCloseKey( hKey );
  98. // Register object, typelib and all interfaces in typelib
  99. //
  100. return _Module.RegisterServer(TRUE);
  101. }
  102. else
  103. {
  104. return REGDB_E_WRITEREGDB;
  105. }
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // DllUnregisterServer - Removes entries from the system registry
  109. STDAPI DllUnregisterServer(void)
  110. {
  111. _Module.UnregisterServer();
  112. RegDeleteKey(HKEY_LOCAL_MACHINE, STR_MDSPREG);
  113. return S_OK;
  114. }