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.

137 lines
4.6 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  6. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  7. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  8. // PURPOSE.
  9. //
  10. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  11. //==============================================================;
  12. #include "stdafx.h"
  13. #include <mmc.h>
  14. #include <winuser.h>
  15. #include <tchar.h>
  16. #include "globals.h"
  17. //
  18. // This is the minimum set of clipboard formats we must implement.
  19. // MMC uses these to get necessary information from our snapin about
  20. // our nodes.
  21. //
  22. // we need to do this to get around MMC.IDL - it explicitly defines
  23. // the clipboard formats as WCHAR types...
  24. #define _T_CCF_DISPLAY_NAME _T("CCF_DISPLAY_NAME")
  25. #define _T_CCF_NODETYPE _T("CCF_NODETYPE")
  26. #define _T_CCF_SZNODETYPE _T("CCF_SZNODETYPE")
  27. #define _T_CCF_SNAPIN_CLASSID _T("CCF_SNAPIN_CLASSID")
  28. //Our snap-in's CLSID
  29. #define _T_CCF_INTERNAL_SNAPIN _T("{6707A300-264F-4BA3-9537-70E304EED9BA}")
  30. //Needed for extended Active Directory Users and Computers snap-in
  31. #define CFSTR_DSOBJECTNAMES TEXT("DsObjectNames")
  32. // These are the clipboard formats that we must supply at a minimum.
  33. // mmc.h actually defined these. We can make up our own to use for
  34. // other reasons.
  35. extern UINT s_cfDisplayName = RegisterClipboardFormat(_T_CCF_DISPLAY_NAME);
  36. extern UINT s_cfNodeType = RegisterClipboardFormat(_T_CCF_NODETYPE);
  37. extern UINT s_cfSZNodeType = RegisterClipboardFormat(_T_CCF_SZNODETYPE);
  38. extern UINT s_cfSnapinClsid = RegisterClipboardFormat(_T_CCF_SNAPIN_CLASSID);
  39. // Custom clipboard format only used within the snap-in
  40. UINT s_cfInternal = RegisterClipboardFormat(_T_CCF_INTERNAL_SNAPIN);
  41. //AD Users and Computers snap-in clip format
  42. extern UINT cfDsObjectNames = (CLIPFORMAT)RegisterClipboardFormat(CFSTR_DSOBJECTNAMES);
  43. // this uses the ATL String Conversion Macros
  44. // for handling any necessary string conversion. Note that
  45. // the snap-in (callee) allocates the necessary memory,
  46. // and MMC (the caller) does the cleanup, as required by COM.
  47. HRESULT AllocOleStr(LPOLESTR *lpDest, _TCHAR *szBuffer)
  48. {
  49. USES_CONVERSION;
  50. *lpDest = static_cast<LPOLESTR>(CoTaskMemAlloc((_tcslen(szBuffer) + 1) *
  51. sizeof(WCHAR)));
  52. if (*lpDest == 0)
  53. return E_OUTOFMEMORY;
  54. LPOLESTR ptemp = T2OLE(szBuffer);
  55. wcscpy(*lpDest, ptemp);
  56. return S_OK;
  57. }
  58. ///////////////////////////////
  59. // Global functions for extracting
  60. // information from a primary's
  61. // data object
  62. ///////////////////////////////
  63. HRESULT ExtractData( IDataObject* piDataObject,
  64. CLIPFORMAT cfClipFormat,
  65. BYTE* pbData,
  66. DWORD cbData )
  67. {
  68. HRESULT hr = S_OK;
  69. FORMATETC formatetc = {cfClipFormat, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  70. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL};
  71. stgmedium.hGlobal = ::GlobalAlloc(GPTR, cbData);
  72. do // false loop
  73. {
  74. if (NULL == stgmedium.hGlobal)
  75. {
  76. hr = E_OUTOFMEMORY;
  77. break;
  78. }
  79. hr = piDataObject->GetDataHere( &formatetc, &stgmedium );
  80. if ( FAILED(hr) )
  81. {
  82. break;
  83. }
  84. BYTE* pbNewData = reinterpret_cast<BYTE*>(stgmedium.hGlobal);
  85. if (NULL == pbNewData)
  86. {
  87. hr = E_UNEXPECTED;
  88. break;
  89. }
  90. ::memcpy( pbData, pbNewData, cbData );
  91. } while (FALSE); // false loop
  92. if (NULL != stgmedium.hGlobal)
  93. {
  94. ::GlobalFree(stgmedium.hGlobal);
  95. }
  96. return hr;
  97. } // ExtractData()
  98. HRESULT ExtractString( IDataObject *piDataObject,
  99. CLIPFORMAT cfClipFormat,
  100. _TCHAR *pstr,
  101. DWORD cchMaxLength)
  102. {
  103. return ExtractData( piDataObject, cfClipFormat, (PBYTE)pstr, cchMaxLength );
  104. }
  105. HRESULT ExtractSnapInCLSID( IDataObject* piDataObject, CLSID* pclsidSnapin )
  106. {
  107. return ExtractData( piDataObject, s_cfSnapinClsid, (PBYTE)pclsidSnapin, sizeof(CLSID) );
  108. }
  109. HRESULT ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType )
  110. {
  111. return ExtractData( piDataObject, s_cfNodeType, (PBYTE)pguidObjectType, sizeof(GUID) );
  112. }