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.

159 lines
4.2 KiB

  1. // **************************************************************************
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation.
  4. //
  5. // File: OAHELP.INL
  6. //
  7. // Description:
  8. // OLE Automation Helpers for client code
  9. //
  10. // History:
  11. //
  12. // **************************************************************************
  13. #ifndef _OAHELP_INL_
  14. #define _OAHELP_INL_
  15. class CBSTR
  16. {
  17. private:
  18. BSTR m_pStr;
  19. public:
  20. CBSTR() { m_pStr = 0; }
  21. CBSTR(LPWSTR pSrc) { m_pStr = SysAllocString(pSrc); }
  22. ~CBSTR() { if (m_pStr) SysFreeString(m_pStr); }
  23. operator BSTR() { return m_pStr; }
  24. void Unbind() { m_pStr = 0; }
  25. };
  26. class CVARIANT
  27. {
  28. private:
  29. VARIANT v;
  30. public:
  31. CVARIANT() { VariantInit(&v); }
  32. ~CVARIANT() { VariantClear(&v); }
  33. void Clear() { VariantClear(&v); }
  34. operator VARIANT *() { return &v; }
  35. VARIANT *operator &() { return &v; }
  36. CVARIANT(LPWSTR pSrc) { VariantInit(&v); SetStr(pSrc); }
  37. CVARIANT(LONG lSrc) { VariantInit(&v); SetLONG(lSrc); }
  38. CVARIANT(BOOL b) { VariantInit(&v); SetBool(b); }
  39. CVARIANT(short i) { VariantInit(&v); SetShort(i); }
  40. CVARIANT(double d) { VariantInit(&v); SetDouble(d); }
  41. CVARIANT(BYTE b) { VariantInit(&v); SetByte(b); }
  42. CVARIANT(IDispatch * pDisp)
  43. {
  44. VariantInit(&v); pDisp->AddRef();
  45. SetDispatch(pDisp);
  46. }
  47. void SetStr(LPWSTR pSrc)
  48. {
  49. Clear();
  50. V_VT(&v) = pSrc ? VT_BSTR : VT_NULL;
  51. V_BSTR(&v) = pSrc ? SysAllocString(pSrc) : 0;
  52. }
  53. LPWSTR GetStr() { return V_VT(&v) == VT_BSTR ? V_BSTR(&v) : 0; }
  54. operator LPWSTR() { return V_VT(&v) == VT_BSTR ? V_BSTR(&v) : 0; }
  55. void SetLONG(LONG lSrc) { Clear(); V_VT(&v) = VT_I4; V_I4(&v) = lSrc; }
  56. LONG GetLONG() { return V_I4(&v); }
  57. operator LONG() { return V_I4(&v); }
  58. void SetDouble(double dSrc)
  59. {
  60. Clear();
  61. V_VT(&v) = VT_R8;
  62. V_R8(&v) = dSrc;
  63. }
  64. double GetDouble() { return V_R8(&v); }
  65. operator double() { return V_R8(&v); }
  66. void SetByte(BYTE bySrc) { Clear(); V_VT(&v) = VT_UI1; V_UI1(&v) = bySrc;}
  67. BYTE GetByte() { return V_UI1(&v); }
  68. operator BYTE() { return V_UI1(&v); }
  69. void SetBool(BOOL b)
  70. {
  71. V_VT(&v) = VT_BOOL;
  72. V_BOOL(&v) = b ? VARIANT_TRUE : VARIANT_FALSE;
  73. }
  74. BOOL GetBool() { return V_BOOL(&v) == VARIANT_TRUE; }
  75. operator BOOL() { return V_BOOL(&v); }
  76. void SetDispatch(IDispatch* pDisp)
  77. {
  78. V_VT(&v) = VT_DISPATCH;
  79. V_DISPATCH(&v) = pDisp;
  80. }
  81. IDispatch * GetDispatch() { return V_DISPATCH(&v); }
  82. void SetUnknown(IUnknown* pUnk)
  83. {
  84. V_VT(&v) = VT_UNKNOWN;
  85. V_UNKNOWN(&v) = pUnk;
  86. }
  87. IUnknown * GetUnknown() { return V_UNKNOWN(&v); }
  88. void SetShort(short i) { V_VT(&v) = VT_I2; V_I2(&v) = i; }
  89. short GetShort() { return V_I2(&v); }
  90. operator short() { return V_I2(&v); }
  91. VARTYPE GetType() { return V_VT(&v); }
  92. void SetArray(SAFEARRAY *p, VARTYPE vt)
  93. {
  94. Clear();
  95. V_VT(&v) = vt;
  96. V_ARRAY(&v) = p;
  97. }
  98. operator SAFEARRAY *() { return (V_VT(&v) & VT_ARRAY ? V_ARRAY(&v) : 0); }
  99. void Unbind() { VariantInit(&v); }
  100. };
  101. class CSAFEARRAY
  102. {
  103. private:
  104. SAFEARRAY *p;
  105. public:
  106. CSAFEARRAY(VARTYPE v, int nSize)
  107. {
  108. SAFEARRAYBOUND rgsabound[1];
  109. rgsabound[0].lLbound = 0;
  110. rgsabound[0].cElements = nSize;
  111. p = SafeArrayCreate(v, 1, rgsabound);
  112. }
  113. ~CSAFEARRAY() { if (p) SafeArrayDestroy(p); }
  114. CSAFEARRAY(SAFEARRAY *pSrc) { p = pSrc; }
  115. HRESULT Put(long nLocation, LPVOID pData) {
  116. return SafeArrayPutElement(p, &nLocation, pData);
  117. }
  118. HRESULT Get(long nLocation, LPVOID pData) {
  119. return SafeArrayGetElement(p, &nLocation, pData);
  120. }
  121. HRESULT Access(void **pData) { return SafeArrayAccessData(p, pData); }
  122. HRESULT Unaccess() { return SafeArrayUnaccessData(p); }
  123. operator SAFEARRAY *() { return p; }
  124. long GetNumElements()
  125. {
  126. long upper;
  127. SafeArrayGetUBound(p, 1, &upper);
  128. return upper + 1;
  129. }
  130. void Unbind() { p = 0; }
  131. };
  132. #endif //#ifndef _OAHELP_INL_