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.

181 lines
4.6 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1999
  5. //
  6. // File: guidhelp.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 9/18/1996 JonN Created
  15. //
  16. //____________________________________________________________________________
  17. #include <objbase.h>
  18. #include <basetyps.h>
  19. #include "dbg.h"
  20. #include "cstr.h"
  21. DECLARE_INFOLEVEL(AMCCore);
  22. #include "commctrl.h" // for LV_ITEM needed by ndmgrpriv.h
  23. // This defines the GUID's in the headers below.
  24. #ifndef DECLSPEC_UUID
  25. #define DECLSPEC_UUID(x) __declspec(uuid(x))
  26. #endif
  27. #include "mmc.h"
  28. #include "ndmgr.h"
  29. #include "ndmgrpriv.h"
  30. #include "guidhelp.h"
  31. #include "comdef.h"
  32. #include "atlbase.h" // USES_CONVERSION
  33. #include "macros.h"
  34. #ifdef _DEBUG
  35. #define new DEBUG_NEW
  36. #undef THIS_FILE
  37. static char THIS_FILE[] = __FILE__;
  38. #endif
  39. static CLIPFORMAT g_CFNodeType = 0;
  40. static CLIPFORMAT g_CFSnapInCLSID = 0;
  41. static CLIPFORMAT g_CFDisplayName = 0;
  42. HRESULT ExtractData( IDataObject* piDataObject,
  43. CLIPFORMAT cfClipFormat,
  44. BYTE* pbData,
  45. DWORD cbData )
  46. {
  47. IF_NULL_RETURN_INVALIDARG2( piDataObject, pbData );
  48. HRESULT hr = S_OK;
  49. FORMATETC formatetc = {cfClipFormat, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  50. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL};
  51. stgmedium.hGlobal = ::GlobalAlloc(GPTR, cbData);
  52. do // false loop
  53. {
  54. if (NULL == stgmedium.hGlobal)
  55. {
  56. ASSERT(FALSE);
  57. ////AfxThrowMemoryException();
  58. hr = E_OUTOFMEMORY;
  59. break;
  60. }
  61. hr = piDataObject->GetDataHere( &formatetc, &stgmedium );
  62. if ( FAILED(hr) )
  63. {
  64. // ASSERT( FALSE );
  65. break;
  66. }
  67. BYTE* pbNewData = reinterpret_cast<BYTE*>(stgmedium.hGlobal);
  68. if (NULL == pbNewData)
  69. {
  70. ASSERT(FALSE);
  71. hr = E_UNEXPECTED;
  72. break;
  73. }
  74. ::memcpy( pbData, pbNewData, cbData );
  75. } while (FALSE); // false loop
  76. if (NULL != stgmedium.hGlobal)
  77. {
  78. #if (_MSC_VER >= 1200)
  79. #pragma warning (push)
  80. #endif
  81. #pragma warning(disable: 4553) // "==" operator has no effect
  82. VERIFY( NULL == ::GlobalFree(stgmedium.hGlobal) );
  83. #if (_MSC_VER >= 1200)
  84. #pragma warning (pop)
  85. #endif
  86. }
  87. return hr;
  88. } // ExtractData()
  89. HRESULT ExtractSnapInCLSID( IDataObject* piDataObject, CLSID* pclsidSnapin )
  90. {
  91. if( !g_CFSnapInCLSID )
  92. {
  93. USES_CONVERSION;
  94. g_CFSnapInCLSID = (CLIPFORMAT) RegisterClipboardFormat(W2T(CCF_SNAPIN_CLASSID));
  95. }
  96. return ExtractData( piDataObject, g_CFSnapInCLSID, (PBYTE)pclsidSnapin, sizeof(CLSID) );
  97. }
  98. HRESULT ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType )
  99. {
  100. if( !g_CFNodeType )
  101. {
  102. USES_CONVERSION;
  103. g_CFNodeType = (CLIPFORMAT) RegisterClipboardFormat(W2T(CCF_NODETYPE));
  104. }
  105. return ExtractData( piDataObject, g_CFNodeType, (PBYTE)pguidObjectType, sizeof(GUID) );
  106. }
  107. HRESULT GuidToCStr( CStr* pstr, const GUID& guid )
  108. {
  109. WCHAR awch[MAX_PATH];
  110. HRESULT hr = StringFromGUID2(guid, awch, sizeof(awch)/sizeof(awch[0]));
  111. ASSERT(SUCCEEDED(hr));
  112. if (FAILED(hr))
  113. return hr;
  114. USES_CONVERSION;
  115. LPTSTR lptstr = OLE2T(awch);
  116. *pstr = lptstr;
  117. return hr;
  118. }
  119. HRESULT CStrToGuid( const CStr& str, GUID* pguid )
  120. {
  121. USES_CONVERSION;
  122. LPOLESTR lpolestr = T2OLE(((LPTSTR)(LPCTSTR)str));
  123. HRESULT hr = CLSIDFromString(lpolestr, pguid);
  124. ASSERT(SUCCEEDED(hr));
  125. return hr;
  126. }
  127. HRESULT ExtractObjectTypeCStr( IDataObject* piDataObject, CStr* pstr )
  128. {
  129. GUID guidObjectType;
  130. HRESULT hr = ExtractObjectTypeGUID( piDataObject, &guidObjectType );
  131. ASSERT(SUCCEEDED(hr));
  132. return GuidToCStr( pstr, guidObjectType );
  133. }
  134. HRESULT LoadRootDisplayName(IComponentData* pIComponentData,
  135. CStr& strDisplayName)
  136. {
  137. IDataObjectPtr spIDataObject;
  138. HRESULT hr = pIComponentData->QueryDataObject(NULL, CCT_SNAPIN_MANAGER, &spIDataObject);
  139. CHECK_HRESULT(hr);
  140. if ( FAILED(hr) )
  141. return hr;
  142. if( !g_CFDisplayName )
  143. {
  144. USES_CONVERSION;
  145. g_CFDisplayName = (CLIPFORMAT) RegisterClipboardFormat(W2T(CCF_DISPLAY_NAME));
  146. }
  147. hr = ExtractString( spIDataObject,
  148. g_CFDisplayName,
  149. strDisplayName);
  150. CHECK_HRESULT(hr);
  151. return hr;
  152. }