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.

371 lines
7.9 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. OLEWRAP.CPP
  5. Abstract:
  6. Wrapper classes for COM data type functions.
  7. If a COM data function is required to allocate memory and fails to do
  8. so, then a CX_MemoryException exception is thrown. All COM data type
  9. functions are wrapped, regardless if they allocate memory, for the sake
  10. of completeness.
  11. History:
  12. a-dcrews 19-Mar-99 Created.
  13. --*/
  14. #include "precomp.h"
  15. #include <corex.h>
  16. #include <oleauto.h>
  17. #include "OleWrap.h"
  18. #include "genutils.h"
  19. //***************************************************************************
  20. //
  21. // SafeArray wrappers
  22. //
  23. //***************************************************************************
  24. HRESULT COleAuto::_SafeArrayAccessData(SAFEARRAY FAR* psa, void HUGEP* FAR* ppvData)
  25. {
  26. return SafeArrayAccessData(psa, ppvData);
  27. }
  28. HRESULT COleAuto::_SafeArrayAllocData(SAFEARRAY FAR* psa)
  29. {
  30. HRESULT hRes = S_OK;
  31. hRes = SafeArrayAllocData(psa);
  32. return hRes;
  33. }
  34. HRESULT COleAuto::_SafeArrayAllocDescriptor(unsigned int cDims, SAFEARRAY FAR* FAR* ppsaOut)
  35. {
  36. HRESULT hRes = S_OK;
  37. hRes = SafeArrayAllocDescriptor(cDims, ppsaOut);
  38. return hRes;
  39. }
  40. HRESULT COleAuto::_SafeArrayCopy(SAFEARRAY FAR* psa, SAFEARRAY FAR* FAR* ppsaOut)
  41. {
  42. HRESULT hRes = S_OK;
  43. hRes = SafeArrayCopy(psa, ppsaOut);
  44. if (E_OUTOFMEMORY == hRes)
  45. {
  46. throw CX_MemoryException();
  47. }
  48. return hRes;
  49. }
  50. HRESULT COleAuto::_SafeArrayCopyData(SAFEARRAY FAR* psaSource, SAFEARRAY FAR* psaTarget)
  51. {
  52. HRESULT hRes = S_OK;
  53. hRes = SafeArrayCopyData(psaSource, psaTarget);
  54. if (E_OUTOFMEMORY == hRes)
  55. {
  56. throw CX_MemoryException();
  57. }
  58. return hRes;
  59. }
  60. SAFEARRAY* COleAuto::_SafeArrayCreate(VARTYPE vt, unsigned int cDims, SAFEARRAYBOUND FAR* rgsabound)
  61. {
  62. SAFEARRAY* psa;
  63. psa = SafeArrayCreate(vt, cDims, rgsabound);
  64. if (NULL == psa)
  65. {
  66. throw CX_MemoryException();
  67. }
  68. return psa;
  69. }
  70. SAFEARRAY* COleAuto::_SafeArrayCreateVector(VARTYPE vt, long lLbound, unsigned int cElements)
  71. {
  72. SAFEARRAY* psa;
  73. psa = SafeArrayCreateVector(vt, lLbound, cElements);
  74. if (NULL == psa)
  75. {
  76. throw CX_MemoryException();
  77. }
  78. return psa;
  79. }
  80. HRESULT COleAuto::_SafeArrayDestroy(SAFEARRAY FAR* psa)
  81. {
  82. return SafeArrayDestroy(psa);
  83. }
  84. HRESULT COleAuto::_SafeArrayDestroyData(SAFEARRAY FAR* psa)
  85. {
  86. return SafeArrayDestroyData(psa);
  87. }
  88. HRESULT COleAuto::_SafeArrayDestroyDescriptor(SAFEARRAY FAR* psa)
  89. {
  90. return SafeArrayDestroyDescriptor(psa);
  91. }
  92. UINT COleAuto::_SafeArrayGetDim(SAFEARRAY FAR* psa)
  93. {
  94. return SafeArrayGetDim(psa);
  95. }
  96. HRESULT COleAuto::_SafeArrayGetElement(SAFEARRAY FAR* psa, long FAR* rgIndices, void FAR* pv)
  97. {
  98. return SafeArrayGetElement(psa, rgIndices, pv);
  99. }
  100. UINT COleAuto::_SafeArrayGetElemsize(SAFEARRAY FAR* psa)
  101. {
  102. return SafeArrayGetElemsize(psa);
  103. }
  104. HRESULT COleAuto::_SafeArrayGetLBound(SAFEARRAY FAR* psa, unsigned int nDim, long FAR* plLbound)
  105. {
  106. return SafeArrayGetLBound(psa, nDim, plLbound);
  107. }
  108. HRESULT COleAuto::_SafeArrayGetUBound(SAFEARRAY FAR* psa, unsigned int nDim, long FAR* plUbound)
  109. {
  110. return SafeArrayGetUBound(psa, nDim, plUbound);
  111. }
  112. HRESULT COleAuto::_SafeArrayLock(SAFEARRAY FAR* psa)
  113. {
  114. return SafeArrayLock(psa);
  115. }
  116. HRESULT COleAuto::_SafeArrayPtrOfIndex(SAFEARRAY FAR* psa, long FAR* rgIndices, void HUGEP* FAR* ppvData)
  117. {
  118. return SafeArrayPtrOfIndex(psa, rgIndices, ppvData);
  119. }
  120. HRESULT COleAuto::_SafeArrayPutElement(SAFEARRAY FAR* psa, long FAR* rgIndices, void FAR* pv)
  121. {
  122. return SafeArrayPutElement(psa, rgIndices, pv);
  123. }
  124. HRESULT COleAuto::_SafeArrayRedim(SAFEARRAY FAR* psa, SAFEARRAYBOUND FAR* psaboundNew)
  125. {
  126. return SafeArrayRedim(psa, psaboundNew);
  127. }
  128. HRESULT COleAuto::_SafeArrayUnaccessData(SAFEARRAY FAR* psa)
  129. {
  130. return SafeArrayUnaccessData(psa);
  131. }
  132. HRESULT COleAuto::_SafeArrayUnlock(SAFEARRAY FAR* psa)
  133. {
  134. return SafeArrayUnlock(psa);
  135. }
  136. //***************************************************************************
  137. //
  138. // Variant wrappers
  139. //
  140. //***************************************************************************
  141. HRESULT COleAuto::_WbemVariantChangeType(VARIANTARG FAR* pvargDest, VARIANTARG FAR* pvarSrc, VARTYPE vt)
  142. {
  143. HRESULT hRes = WbemVariantChangeType(pvargDest, pvarSrc, vt);
  144. if (E_OUTOFMEMORY == hRes)
  145. {
  146. throw CX_MemoryException();
  147. }
  148. return hRes;
  149. }
  150. HRESULT COleAuto::_VariantChangeType(VARIANTARG FAR* pvargDest, VARIANTARG FAR* pvarSrc, unsigned short wFlags, VARTYPE vt)
  151. {
  152. HRESULT hRes = VariantChangeType(pvargDest, pvarSrc, wFlags, vt);
  153. if (E_OUTOFMEMORY == hRes)
  154. {
  155. throw CX_MemoryException();
  156. }
  157. return hRes;
  158. }
  159. HRESULT COleAuto::_VariantChangeTypeEx(VARIANTARG FAR* pvargDest, VARIANTARG FAR* pvarSrc, LCID lcid, unsigned short wFlags, VARTYPE vt)
  160. {
  161. HRESULT hRes = VariantChangeTypeEx(pvargDest, pvarSrc, lcid, wFlags, vt);
  162. if (E_OUTOFMEMORY == hRes)
  163. {
  164. throw CX_MemoryException();
  165. }
  166. return hRes;
  167. }
  168. HRESULT COleAuto::_VariantClear(VARIANTARG FAR* pvarg)
  169. {
  170. return VariantClear(pvarg);
  171. }
  172. HRESULT COleAuto::_VariantCopy(VARIANTARG FAR* pvargDest, VARIANTARG FAR* pvargSrc)
  173. {
  174. HRESULT hRes = VariantCopy(pvargDest, pvargSrc);
  175. if (E_OUTOFMEMORY == hRes)
  176. {
  177. throw CX_MemoryException();
  178. }
  179. return hRes;
  180. }
  181. HRESULT COleAuto::_VariantCopyInd(VARIANT FAR* pvarDest, VARIANTARG FAR* pvargSrc)
  182. {
  183. HRESULT hRes = VariantCopyInd(pvarDest, pvargSrc);
  184. if (E_OUTOFMEMORY == hRes)
  185. {
  186. throw CX_MemoryException();
  187. }
  188. return hRes;
  189. }
  190. void COleAuto::_VariantInit(VARIANTARG FAR* pvarg)
  191. {
  192. VariantInit(pvarg);
  193. }
  194. //***************************************************************************
  195. //
  196. // BSTR wrappers
  197. //
  198. //***************************************************************************
  199. BSTR COleAuto::_SysAllocString(const OLECHAR* sz)
  200. {
  201. BSTR bstr = SysAllocString(sz);
  202. if (NULL == bstr)
  203. {
  204. throw CX_MemoryException();
  205. }
  206. return bstr;
  207. }
  208. BSTR COleAuto::_SysAllocStringByteLen(LPCSTR psz, UINT len)
  209. {
  210. BSTR bstr = SysAllocStringByteLen(psz, len);
  211. if (NULL == bstr)
  212. {
  213. throw CX_MemoryException();
  214. }
  215. return bstr;
  216. }
  217. BSTR COleAuto::_SysAllocStringLen(const OLECHAR* pch, UINT cch)
  218. {
  219. BSTR bstr = SysAllocStringLen(pch, cch);
  220. if (NULL == bstr)
  221. {
  222. throw CX_MemoryException();
  223. }
  224. return bstr;
  225. }
  226. void COleAuto::_SysFreeString(BSTR bstr)
  227. {
  228. SysFreeString(bstr);
  229. }
  230. HRESULT COleAuto::_SysReAllocString(BSTR* pbstr, const OLECHAR* sz)
  231. {
  232. HRESULT hRes = SysReAllocString(pbstr, sz);
  233. if (FAILED(hRes))
  234. {
  235. throw CX_MemoryException();
  236. }
  237. return hRes;
  238. }
  239. HRESULT COleAuto::_SysReAllocStringLen(BSTR* pbstr, const OLECHAR* pch, UINT cch)
  240. {
  241. HRESULT hRes = SysReAllocStringLen(pbstr, pch, cch);
  242. if (FAILED(hRes))
  243. {
  244. throw CX_MemoryException();
  245. }
  246. return hRes;
  247. }
  248. HRESULT COleAuto::_SysStringByteLen(BSTR bstr)
  249. {
  250. return SysStringByteLen(bstr);
  251. }
  252. HRESULT COleAuto::_SysStringLen(BSTR bstr)
  253. {
  254. return SysStringLen(bstr);
  255. }
  256. //***************************************************************************
  257. //
  258. // Conversion wrappers
  259. //
  260. //***************************************************************************
  261. HRESULT COleAuto::_VectorFromBstr (BSTR bstr, SAFEARRAY ** ppsa)
  262. {
  263. HRESULT hRes = VectorFromBstr(bstr, ppsa);
  264. if (E_OUTOFMEMORY == hRes)
  265. {
  266. throw CX_MemoryException();
  267. }
  268. return hRes;
  269. }
  270. HRESULT COleAuto::_BstrFromVector (SAFEARRAY *psa, BSTR *pbstr)
  271. {
  272. HRESULT hRes = BstrFromVector(psa, pbstr);
  273. if (E_OUTOFMEMORY == hRes)
  274. {
  275. throw CX_MemoryException();
  276. }
  277. return hRes;
  278. }