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.

130 lines
3.9 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. //
  6. //
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. // PURPOSE.
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //
  17. //==============================================================;
  18. #ifndef _CPropSheetExtension_H_
  19. #define _CPropSheetExtension_H_
  20. #include <tchar.h>
  21. #include <mmc.h>
  22. class CPropSheetExtension : public IExtendPropertySheet
  23. {
  24. private:
  25. ULONG m_cref;
  26. // clipboard format
  27. static UINT s_cfDisplayName;
  28. static UINT s_cfSnapInCLSID;
  29. static UINT s_cfNodeType;
  30. public:
  31. CPropSheetExtension();
  32. ~CPropSheetExtension();
  33. ///////////////////////////////
  34. // Interface IUnknown
  35. ///////////////////////////////
  36. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  37. STDMETHODIMP_(ULONG) AddRef();
  38. STDMETHODIMP_(ULONG) Release();
  39. ///////////////////////////////
  40. // Interface IExtendPropertySheet
  41. ///////////////////////////////
  42. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE CreatePropertyPages(
  43. /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,
  44. /* [in] */ LONG_PTR handle,
  45. /* [in] */ LPDATAOBJECT lpIDataObject);
  46. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE QueryPagesFor(
  47. /* [in] */ LPDATAOBJECT lpDataObject);
  48. private:
  49. LONG_PTR m_ppHandle;
  50. static BOOL CALLBACK DialogProc(HWND hwndDlg, // handle to dialog box
  51. UINT uMsg, // message
  52. WPARAM wParam, // first message parameter
  53. LPARAM lParam // second message parameter
  54. );
  55. ///////////////////////////////
  56. // Private IDataObject support bits
  57. ///////////////////////////////
  58. HRESULT ExtractData( IDataObject* piDataObject,
  59. CLIPFORMAT cfClipFormat,
  60. BYTE* pbData,
  61. DWORD cbData )
  62. {
  63. HRESULT hr = S_OK;
  64. FORMATETC formatetc = {cfClipFormat, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  65. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL};
  66. stgmedium.hGlobal = ::GlobalAlloc(GPTR, cbData);
  67. do // false loop
  68. {
  69. if (NULL == stgmedium.hGlobal)
  70. {
  71. hr = E_OUTOFMEMORY;
  72. break;
  73. }
  74. hr = piDataObject->GetDataHere( &formatetc, &stgmedium );
  75. if ( FAILED(hr) )
  76. {
  77. break;
  78. }
  79. BYTE* pbNewData = reinterpret_cast<BYTE*>(stgmedium.hGlobal);
  80. if (NULL == pbNewData)
  81. {
  82. hr = E_UNEXPECTED;
  83. break;
  84. }
  85. ::memcpy( pbData, pbNewData, cbData );
  86. } while (FALSE); // false loop
  87. if (NULL != stgmedium.hGlobal)
  88. {
  89. ::GlobalFree(stgmedium.hGlobal);
  90. }
  91. return hr;
  92. } // ExtractData()
  93. HRESULT ExtractString( IDataObject *piDataObject,
  94. CLIPFORMAT cfClipFormat,
  95. _TCHAR *pstr,
  96. DWORD cchMaxLength)
  97. {
  98. return ExtractData( piDataObject, cfClipFormat, (PBYTE)pstr, cchMaxLength );
  99. }
  100. HRESULT ExtractSnapInCLSID( IDataObject* piDataObject, CLSID* pclsidSnapin )
  101. {
  102. return ExtractData( piDataObject, s_cfSnapInCLSID, (PBYTE)pclsidSnapin, sizeof(CLSID) );
  103. }
  104. HRESULT ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType )
  105. {
  106. return ExtractData( piDataObject, s_cfNodeType, (PBYTE)pguidObjectType, sizeof(GUID) );
  107. }
  108. };
  109. #endif _CPropSheetExtension_H_