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.

216 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: thoputil.hxx
  7. //
  8. // Contents: Thunk routine utilities
  9. //
  10. // History: 01-Mar-94 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #ifndef __THOPUTIL_HXX__
  14. #define __THOPUTIL_HXX__
  15. // Alias manager for THOP_ALIAS32
  16. extern CAliases gAliases32;
  17. IIDIDX IidToIidIdx(REFIID riid);
  18. #ifdef COTASK_DEFINED
  19. #define TaskMalloc32 CoTaskMemAlloc
  20. #define TaskFree32 CoTaskMemFree
  21. #else
  22. LPVOID TaskMalloc32(SIZE_T cb);
  23. void TaskFree32(LPVOID pv);
  24. #endif
  25. DWORD TaskMalloc16( UINT uiSize );
  26. void TaskFree16( DWORD vpvoid );
  27. LPOLESTR Convert_VPSTR_to_LPOLESTR(THUNKINFO *pti,
  28. VPSTR vpstr,
  29. LPOLESTR lpOleStr,
  30. UINT uiSizeInPlace);
  31. //
  32. // Simple macro to free up any string allocated in the conversion process
  33. //
  34. #define Convert_VPSTR_to_LPOLESTR_free( lpOleStr, lpOleStrUsed ) \
  35. (((lpOleStr) == (lpOleStrUsed)) ? 0 : \
  36. (lpOleStrUsed == NULL) ? 0 : TaskFree32(lpOleStrUsed))
  37. SCODE Convert_LPOLESTR_to_VPSTR(LPCOLESTR lpOleStr,
  38. VPSTR vpstr,
  39. UINT uiSize32,
  40. UINT uiSize16);
  41. #ifdef _CHICAGO_
  42. // This is only really used on Chicago
  43. SCODE Convert_LPSTR_to_VPSTR(LPCSTR lpOleStr,
  44. VPSTR vpstr,
  45. UINT uiSize32,
  46. UINT uiSize16);
  47. #endif
  48. STDAPI_(DWORD) TransformHRESULT_1632( DWORD hresult );
  49. STDAPI_(DWORD) TransformHRESULT_3216( DWORD hresult );
  50. SHORT ClampLongToShort(LONG l);
  51. USHORT ClampULongToUShort(ULONG l);
  52. VOID * GetReadPtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  53. VOID * GetWritePtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  54. VOID * GetCodePtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  55. VOID * GetReadWritePtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  56. CHAR * GetStringPtr16( THUNKINFO *pti, VPVOID vp16, UINT cchMax,
  57. PUINT lpuiSize );
  58. VOID * ValidatePtr16(THUNKINFO *pti, VPVOID vp16, DWORD dwSize,
  59. THOP thopInOut);
  60. BOOL IsValidInterface16( THUNKINFO *pti, VPVOID vp );
  61. SCODE ConvertHGlobal1632(THUNKINFO *pti,
  62. HMEM16 hg16,
  63. THOP thopInOut,
  64. HGLOBAL *phg32,
  65. DWORD *pdwSize);
  66. SCODE ConvertHGlobal3216(THUNKINFO *pti,
  67. HGLOBAL hg32,
  68. THOP thopInOut,
  69. HMEM16 *phg16,
  70. DWORD *pdwSize);
  71. SCODE ConvertStgMed1632(THUNKINFO *pti,
  72. VPVOID vpsm16,
  73. STGMEDIUM *psm32,
  74. FORMATETC *pfe,
  75. BOOL fPassingOwnershipIn,
  76. DWORD *pdwSize);
  77. SCODE CleanStgMed32(THUNKINFO *pti,
  78. STGMEDIUM *psm32,
  79. VPVOID vpsm16,
  80. DWORD dwSize,
  81. BOOL fIsThunk,
  82. FORMATETC *pfe);
  83. SCODE ConvertStgMed3216(THUNKINFO *pti,
  84. STGMEDIUM *psm32,
  85. VPVOID vpsm16,
  86. FORMATETC *pfe,
  87. BOOL fPassingOwnershipIn,
  88. DWORD *pdwSize);
  89. SCODE CleanStgMed16(THUNKINFO *pti,
  90. VPVOID vpsm16,
  91. STGMEDIUM *psm32,
  92. DWORD dwSize,
  93. BOOL fIsThunk,
  94. FORMATETC *pfe);
  95. SCODE ConvertFetc1632(THUNKINFO *pti,
  96. VPVOID vpfe16,
  97. FORMATETC *pfe32,
  98. BOOL fFree);
  99. SCODE ConvertFetc3216(THUNKINFO *pti,
  100. FORMATETC *pfe32,
  101. VPVOID vpfe16,
  102. BOOL fFree);
  103. #if DBG == 1
  104. char *ThopName(THOP thop);
  105. char *EnumThopName(THOP thopEnum);
  106. char *GuidString(GUID const *pguid);
  107. char *IidOrInterfaceString(IID const *piid);
  108. char *IidIdxString(IIDIDX iidx);
  109. void DebugValidateProxy1632(VPVOID vpvProxy);
  110. void DebugValidateProxy3216(THUNK3216OBJ *ptoProxy);
  111. #else
  112. #define DebugValidateProxy1632(p)
  113. #define DebugValidateProxy3216(p)
  114. #endif
  115. #define StackAlloc16(cb) \
  116. ((VPVOID)TlsThkGetStack16()->Alloc(cb))
  117. #define StackFree16(vpv, cb) \
  118. TlsThkGetStack16()->Free((DWORD)vpv, cb)
  119. #define StackAlloc32(cb) \
  120. ((LPVOID)TlsThkGetStack32()->Alloc(cb))
  121. #define StackFree32(pv, cb) \
  122. TlsThkGetStack32()->Free((DWORD)pv, cb)
  123. #define STACKALLOC16(x) StackAlloc16(x)
  124. #define STACKFREE16(x,y) StackFree16(x, y)
  125. #ifdef _CHICAGO_
  126. #define STACKALLOC32(x) StackAlloc32(x)
  127. #define STACKFREE32(x, y) StackFree32(x, y)
  128. #else
  129. #define STACKALLOC32(x) (DWORD)_alloca(x)
  130. #define STACKFREE32(x, y)
  131. #endif
  132. #if DBG == 1
  133. void RecordStackState16(SStackRecord *psr);
  134. void CheckStackState16(SStackRecord *psr);
  135. void RecordStackState32(SStackRecord *psr);
  136. void CheckStackState32(SStackRecord *psr);
  137. #endif
  138. typedef void *(*ALLOCROUTINE)(UINT cb);
  139. typedef void (*FREEROUTINE)(void *pv, UINT cb);
  140. void *ArTask16(UINT cb);
  141. void FrTask16(void *pv, UINT cb);
  142. void *ArTask32(UINT cb);
  143. void FrTask32(void *pv, UINT cb);
  144. void *ArStack16(UINT cb);
  145. void FrStack16(void *pv, UINT cb);
  146. void *ArStack32(UINT cb);
  147. void FrStack32(void *pv, UINT cb);
  148. SCODE ConvertDvtd1632(THUNKINFO *pti,
  149. VPVOID vpdvtd16,
  150. ALLOCROUTINE pfnAlloc,
  151. FREEROUTINE pfnFree,
  152. DVTARGETDEVICE **ppdvtd32,
  153. UINT *pcbSize);
  154. SCODE ConvertDvtd3216(THUNKINFO *pti,
  155. DVTARGETDEVICE *pdvtd32,
  156. ALLOCROUTINE pfnAlloc,
  157. FREEROUTINE pfnFree,
  158. VPVOID *ppvdvtd16,
  159. UINT *pcbSize);
  160. typedef void (*FIXEDHANDLERROUTINE)(BYTE *pbFrom, BYTE *pbTo,
  161. UINT cbFrom, UINT cbTo);
  162. void FhCopyMemory(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  163. void FhShortToLong(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  164. void FhLongToShort(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  165. void FhWordToDword(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  166. void FhDwordToWord(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  167. void FhGdiHandle1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  168. void FhGdiHandle3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  169. void FhUserHandle1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  170. void FhUserHandle3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  171. void FhHaccel1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  172. void FhHaccel3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  173. void FhHtask1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  174. void FhHtask3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  175. void FhHresult1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  176. void FhHresult3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  177. void FhNull(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  178. void FhRect1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  179. void FhRect3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  180. void FhSize1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  181. void FhSize3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  182. void FhMsg1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  183. void FhMsg3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  184. #endif // #ifndef __THOPUTIL_HXX__