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.

135 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Simply3D.cpp
  5. Abstract:
  6. From Tomislav Markoc:
  7. MSPaint calls OleGetClipboard to get IDataObject interface and then
  8. calls IDataObject::GetData. This call gets marshaled to Simply 3D
  9. GetData.
  10. FORMATETC looks like:
  11. cfFormat=8(CF_DIB) or 2(CF_BITMAP)
  12. ptd=0
  13. dwAspect=1
  14. lindex= -1
  15. tymed=1(TYMED_HGLOBAL) or 16(TYMED_GDI)
  16. Simply 3D returns STGMEDIUM:
  17. tymed=0 //WRONG
  18. hBitmap=hGlobal=some handle !=0
  19. pUnkForRelease=0
  20. STGMEDIUM::tymed should be changed with something like this:
  21. if (STGMEDIUM::tymed==0 && STGMEDIUM::hBitmap &&
  22. (FORMATETC::tymed==TYMED_HGLOBAL || FORMATETC::tymed==TYMED_GDI))
  23. STGMEDIUM::tymed=FORMATETC::tymed;
  24. Notes:
  25. This is an app specific shim.
  26. History:
  27. 02/22/2000 linstev Created
  28. --*/
  29. #include "precomp.h"
  30. IMPLEMENT_SHIM_BEGIN(Simply3D)
  31. #include "ShimHookMacro.h"
  32. APIHOOK_ENUM_BEGIN
  33. APIHOOK_ENUM_ENTRY(OleSetClipboard)
  34. APIHOOK_ENUM_ENTRY_COMSERVER(OLE32)
  35. APIHOOK_ENUM_END
  36. IMPLEMENT_COMSERVER_HOOK(OLE32)
  37. #define CLSID_DataObject IID_IDataObject
  38. typedef HRESULT (*_pfn_IDataObject_GetData)(PVOID pThis, FORMATETC *pFormatetc, STGMEDIUM *pmedium);
  39. typedef HRESULT (*_pfn_OleSetClipboard)(IDataObject * pDataObj);
  40. /*++
  41. Hook OleSetClipboard to hook the object.
  42. --*/
  43. HRESULT
  44. APIHOOK(OleSetClipboard)(
  45. IDataObject *pDataObj
  46. )
  47. {
  48. HRESULT hReturn = ORIGINAL_API(OleSetClipboard)(pDataObj);
  49. if (hReturn == NOERROR) {
  50. HookObject(
  51. NULL,
  52. IID_IDataObject,
  53. (PVOID *) &pDataObj,
  54. NULL,
  55. FALSE);
  56. }
  57. return hReturn;
  58. }
  59. /*++
  60. Hook GetData and correct the return values as
  61. --*/
  62. HRESULT
  63. COMHOOK(IDataObject, GetData)(
  64. PVOID pThis,
  65. FORMATETC *pFormatetc,
  66. STGMEDIUM *pmedium
  67. )
  68. {
  69. HRESULT hrReturn = E_FAIL;
  70. _pfn_IDataObject_GetData pfnOld =
  71. ORIGINAL_COM(IDataObject, GetData, pThis);
  72. if (pfnOld) {
  73. hrReturn = (*pfnOld)(pThis, pFormatetc, pmedium);
  74. if (!pmedium->tymed && pmedium->hBitmap &&
  75. ((pFormatetc->tymed == TYMED_HGLOBAL) ||
  76. (pFormatetc->tymed == TYMED_GDI))) {
  77. LOGN( eDbgLevelError, "[IDataObject_GetData] fixing tymed parameter");
  78. pmedium->tymed = pFormatetc->tymed;
  79. }
  80. }
  81. return hrReturn;
  82. }
  83. /*++
  84. Register hooked functions
  85. --*/
  86. HOOK_BEGIN
  87. APIHOOK_ENTRY_COMSERVER(OLE32)
  88. APIHOOK_ENTRY(OLE32.DLL, OleSetClipboard)
  89. COMHOOK_ENTRY(DataObject, IDataObject, GetData, 3)
  90. HOOK_END
  91. IMPLEMENT_SHIM_END