Source code of Windows XP (NT5)
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.

90 lines
2.5 KiB

  1. // DOManage.cpp - The snap-in manager-specific version of
  2. // CDataObject
  3. //
  4. // Copyright (c) 1998-1999 Microsoft Corporation
  5. #include "StdAfx.h"
  6. #include "DataObj.h"
  7. /*
  8. * CreateDisplayName - Return the text that displays as the root node
  9. * for the snap-in.
  10. *
  11. * History: a-jsari 9/28/97
  12. *
  13. * Note: The hGlobal in lpMedium must be freed by the caller. (See Create for
  14. * details).
  15. */
  16. HRESULT CManagerDataObject::CreateDisplayName(LPSTGMEDIUM lpMedium)
  17. {
  18. CString strDisplayName;
  19. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  20. USES_CONVERSION;
  21. CDataSource *pDataSource = pSource();
  22. if (pDataSource == NULL)
  23. {
  24. FORMATETC fmtMachine = {(CLIPFORMAT) CDataObject::m_cfMachineName, NULL, DVASPECT_CONTENT, TYMED_HGLOBAL};
  25. STGMEDIUM stgMachine;
  26. stgMachine.tymed = TYMED_HGLOBAL;
  27. stgMachine.hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, (MAX_PATH + 1)* sizeof(WCHAR));
  28. stgMachine.pUnkForRelease = NULL;
  29. HRESULT hr = GetDataHere(&fmtMachine, &stgMachine);
  30. if (hr == S_OK)
  31. {
  32. CString strMachine = W2T((LPWSTR)::GlobalLock(stgMachine.hGlobal));
  33. ::GlobalUnlock(stgMachine.hGlobal);
  34. HGLOBAL hGlobal = ::GlobalFree(stgMachine.hGlobal);
  35. ASSERT(hGlobal == NULL);
  36. if (strMachine.Left(2) != CString(_T("\\\\")))
  37. strMachine = CString(_T("\\\\")) + strMachine;
  38. strDisplayName.Format(IDS_NODENAME, strMachine);
  39. }
  40. else
  41. strDisplayName.LoadString(IDS_DESCRIPTION);
  42. }
  43. else
  44. {
  45. VERIFY(pSource()->GetNodeName(strDisplayName));
  46. }
  47. return Create(reinterpret_cast<const void *>(WSTR_FROM_CSTRING(strDisplayName)),
  48. ((strDisplayName.GetLength() + 1) * sizeof(WCHAR)), lpMedium);
  49. }
  50. /*
  51. * CreateNodeTypeData - Return the NodeType for the root node in lpMedium's
  52. * hGlobal pointer.
  53. *
  54. * History: a-jsari 9/28/97 Initial version
  55. *
  56. * Note: The hGlobal in lpMedium must be freed by the caller. (See Create for
  57. * details).
  58. */
  59. HRESULT CManagerDataObject::CreateNodeTypeData(LPSTGMEDIUM pMedium)
  60. {
  61. // Create the node type object in GUID format
  62. return Create(reinterpret_cast<const void *>(&cNodeTypeStatic), sizeof(GUID), pMedium);
  63. }
  64. /*
  65. * CreateNodeTypeStringData - Return the root node's NodeType in string form
  66. * in lpMedium's hGlobal pointer
  67. *
  68. * History: a-jsari 9/28/97 Initial version
  69. *
  70. * Note: The hGlobal in lpMedium must be freed by the caller. (See Create for
  71. * details).
  72. */
  73. HRESULT CManagerDataObject::CreateNodeTypeStringData(LPSTGMEDIUM pMedium)
  74. {
  75. USES_CONVERSION;
  76. return Create(WSTR_FROM_CSTRING(cszNodeTypeStatic),
  77. ((_tcslen(cszNodeTypeStatic) + 1) * sizeof(WCHAR)), pMedium);
  78. }