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.

172 lines
3.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Module : Common
  4. // Description : Common routines for ST projects
  5. //
  6. // File : genobjdefs.h
  7. // Author : kulor
  8. // Date : 05/08/2000
  9. //
  10. // History :
  11. //
  12. ///////////////////////////////////////////////////////////////////////////
  13. #pragma once
  14. ///////////////////////////////////////////////////////////////////////////
  15. #define IN
  16. #define OUT
  17. #define INOUT
  18. #define SAFE_RELEASEIX(x) if (x) { (x)->Release() ; (x) = NULL; }
  19. #define SAFE_DELETEARRAY(a) if (a) { delete [] (a) ; (a) = NULL; }
  20. #define ARRAY_SIZE(x) ( sizeof (x) / sizeof (x[0]) )
  21. #define FAILEDHR_BREAK(hr) if(FAILED(hr) == TRUE){ \
  22. break; \
  23. }
  24. #define FAILEDDW_BREAK(dw) if(dw != 0L){ \
  25. hr = HRESULT_FROM_WIN32(dw); \
  26. break; \
  27. }
  28. ///////////////////////////////////////////////////////////////////////////
  29. template < class K >
  30. class CFakeComObject : public K {
  31. public:
  32. ULONG AddRef (void) { return 1; }
  33. ULONG Release (void) { return 1; }
  34. HRESULT QueryInterface ( REFIID riid, LPVOID* ppVoid )
  35. { return E_FAIL ; }
  36. };
  37. ///////////////////////////////////////////////////////////////////////////
  38. ///////////////////////////////////////////////////////////////////////////
  39. //
  40. // VARIANT -- Helper functions..
  41. //
  42. __inline int IsBSTR(const VARIANT &rv)
  43. {
  44. return (rv.vt == VT_BSTR) ||
  45. (rv.vt == (VT_BYREF | VT_BSTR)) ||
  46. ((rv.vt == (VT_BYREF | VT_VARIANT)) && (rv.pvarVal->vt == VT_BSTR));
  47. }
  48. __inline const BSTR &GetBSTR(const VARIANT &rv)
  49. {
  50. if(rv.vt == VT_BSTR)
  51. {
  52. return rv.bstrVal;
  53. }
  54. else if(rv.vt == (VT_BYREF | VT_BSTR))
  55. {
  56. return *(rv.pbstrVal);
  57. }
  58. else if((rv.vt == (VT_BYREF | VT_VARIANT)) && (rv.pvarVal->vt == VT_BSTR))
  59. {
  60. return rv.pvarVal->bstrVal;
  61. }
  62. else
  63. {
  64. return rv.bstrVal;
  65. }
  66. }
  67. __inline int IsInteger(const VARIANT &rv)
  68. {
  69. return (rv.vt == VT_I4) ||
  70. (rv.vt == (VT_BYREF | VT_I4)) ||
  71. ((rv.vt == (VT_BYREF | VT_VARIANT)) && (rv.pvarVal->vt == VT_I4))||
  72. (rv.vt == VT_I2) ||
  73. (rv.vt == (VT_BYREF | VT_I2)) ||
  74. ((rv.vt == (VT_BYREF | VT_VARIANT)) && (rv.pvarVal->vt == VT_I2));
  75. }
  76. __inline int GetInteger(const VARIANT &rv)
  77. {
  78. if(rv.vt == VT_I4)
  79. {
  80. return rv.lVal;
  81. }
  82. else if(rv.vt == (VT_BYREF | VT_I4))
  83. {
  84. return *(rv.plVal);
  85. }
  86. else if((rv.vt == (VT_BYREF | VT_VARIANT)) && (rv.pvarVal->vt == VT_I4))
  87. {
  88. return rv.pvarVal->lVal;
  89. }
  90. else if(rv.vt == VT_I2)
  91. {
  92. return rv.iVal;
  93. }
  94. else if(rv.vt == (VT_BYREF | VT_I2))
  95. {
  96. return *(rv.piVal);
  97. }
  98. else if((rv.vt == (VT_BYREF | VT_VARIANT)) && (rv.pvarVal->vt == VT_I2))
  99. {
  100. return rv.pvarVal->iVal;
  101. }
  102. else
  103. {
  104. return -1;
  105. }
  106. }
  107. ///////////////////////////////////////////////////////////////////////////
  108. /*
  109. *
  110. * Work in progress
  111. *
  112. template < class K >
  113. class CGenericPool {
  114. public:
  115. CGenericPool ()
  116. {
  117. m_pchData = malloc (INITIAL_POOL_SIZE)
  118. m_cData = INITIAL_POOL_SIZE;
  119. }
  120. LONG GrowBy ( LONG cItems )
  121. {
  122. realloc ( m_pchData , sizeof (K) * (m_cData + cItems) );
  123. for ( long nIndex=0 ; nIndex < cItems ; nIndex++ ) {
  124. m_stackFreeNodes.Push ( nIndex );
  125. }
  126. return m_stackFreeNodes.GetSize();
  127. }
  128. K* AllocNode ( void )
  129. {
  130. if ( m_stackFreeNodes.IsEmpty () ) {
  131. if ( GrowBy ( m_cGrowBy ) == 0 )
  132. return NULL;
  133. }
  134. LONG nIndex = m_stackFreeNodes.Pop ();
  135. return reinterpret_cast < K* > ( m_pchData[nIndex] );
  136. }
  137. FreeNode ( K* )
  138. {
  139. }
  140. protected:
  141. K *m_pchData;
  142. LONG m_cData;
  143. CGenStack m_stackFreeNodes;
  144. };
  145. */
  146. ///////////////////////////////////////////////////////////////////////////