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.

139 lines
4.0 KiB

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