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.

107 lines
4.9 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Description:
  6. // This header file defines stuff published by SEO to other (Microsoft
  7. // internal) projects in additon to the seo.idl file.
  8. //
  9. //-----------------------------------------------------------------------------
  10. #ifndef __SEOEXPORTS_H__
  11. #define __SEOEXPORTS_H__
  12. class CStringGUID {
  13. public:
  14. CStringGUID() { m_bValid=FALSE; };
  15. CStringGUID(const CStringGUID& objGuid) { m_bValid=FALSE; Assign(objGuid); };
  16. CStringGUID(REFGUID rGuid) { m_bValid=FALSE; Assign(rGuid); };
  17. CStringGUID(LPCOLESTR pszGuid) { m_bValid=FALSE; Assign(pszGuid); };
  18. CStringGUID(LPCSTR pszGuid) { m_bValid=FALSE; Assign(pszGuid); };
  19. CStringGUID(const VARIANT *pvarGuid) { m_bValid=FALSE; Assign(pvarGuid); };
  20. CStringGUID(const VARIANT& varGuid) { m_bValid=FALSE; Assign(varGuid); };
  21. CStringGUID(REFGUID rGuid, DWORD dwIndex) {
  22. GUID tmp = rGuid;
  23. tmp.Data4[7] |= 0x80;
  24. tmp.Data2 = (WORD) (dwIndex >> 16);
  25. tmp.Data3 = (WORD) dwIndex;
  26. Assign(rGuid,dwIndex); };
  27. BOOL ReCalcFromGuid() {
  28. m_bValid = FALSE;
  29. if (SUCCEEDED(StringFromGUID2(m_guid,m_szGuidW,sizeof(m_szGuidW)/sizeof(m_szGuidW[0])))) {
  30. ATLW2AHELPER(m_szGuidA,m_szGuidW,sizeof(m_szGuidA)/sizeof(m_szGuidA[0])); m_bValid=TRUE; };
  31. #ifdef DEBUG
  32. USES_CONVERSION;
  33. _ASSERTE(!m_bValid||(!strcmp(W2A(m_szGuidW),m_szGuidA)&&!wcscmp(m_szGuidW,A2W(m_szGuidA))));
  34. #endif
  35. return (m_bValid); };
  36. BOOL CalcNew() {
  37. if (!SUCCEEDED(CoCreateGuid(&m_guid))) { m_bValid=FALSE; return (FALSE); };
  38. return (ReCalcFromGuid()); };
  39. BOOL CalcFromProgID(LPCOLESTR pszProgID) {
  40. if (!pszProgID || !SUCCEEDED(CLSIDFromProgID(pszProgID,&m_guid))) {
  41. m_bValid=FALSE; return (FALSE); };
  42. return (ReCalcFromGuid()); };
  43. BOOL CalcFromProgID(LPCSTR pszProgID) {
  44. USES_CONVERSION; return (CalcFromProgID(pszProgID?A2W(pszProgID):NULL)); };
  45. BOOL Assign(const CStringGUID& objGuid) { operator =(objGuid); return (m_bValid); };
  46. BOOL Assign(REFGUID rGuid) { operator =(rGuid); return (m_bValid); };
  47. BOOL Assign(LPCOLESTR pszGuid) { operator =(pszGuid); return (m_bValid); };
  48. BOOL Assign(LPCSTR pszGuid) { operator =(pszGuid); return (m_bValid); };
  49. BOOL Assign(const VARIANT *pvarGuid) { operator =(pvarGuid); return (m_bValid); };
  50. BOOL Assign(const VARIANT& varGuid) { operator =(varGuid); return (m_bValid); };
  51. BOOL Assign(REFGUID rGuid, DWORD dwIndex) {
  52. // For index'ed GUID's, we set the high-bit of the MAC-address in the GUID - this
  53. // is the multicast bit, and will never be set for any real MAC-address. Then we
  54. // XOR the index value over the Data2 and Data 3 fields of the GUID. Since we
  55. // leave the timestamp fields completely untouched, confidence is "high" that this
  56. // algorithm will never create collisions with any other GUID's.
  57. GUID tmp = rGuid;
  58. tmp.Data4[2] |= 0x80;
  59. tmp.Data2 ^= (WORD) (dwIndex >> 16);
  60. tmp.Data3 ^= (WORD) dwIndex;
  61. operator =(tmp);
  62. return (m_bValid); };
  63. BOOL GetIndex(REFGUID rGuid, DWORD *dwIndex) {
  64. // check to see if this is an indexed GUID by seeing if the
  65. // multicast bit is set to 1
  66. if ((m_guid.Data4[2] & 0x80) != 0x80) return FALSE;
  67. *dwIndex = 0;
  68. // get the high part
  69. *dwIndex = ((WORD) (rGuid.Data2) ^ (m_guid.Data2)) << 16;
  70. // get the low part
  71. *dwIndex += (WORD) ((rGuid.Data3) ^ (m_guid.Data3));
  72. // This does not check that rGuid mangles into m_guid
  73. // if you run it through the index function with dwIndex
  74. return TRUE;
  75. }
  76. operator REFGUID() { _ASSERTE(m_bValid); return (m_guid); };
  77. operator LPCOLESTR() { _ASSERTE(m_bValid); return (m_szGuidW); };
  78. operator LPCSTR() { _ASSERTE(m_bValid); return (m_szGuidA); };
  79. const CStringGUID& operator =(const CStringGUID& objGuid) {
  80. if (!objGuid) { m_bValid=FALSE; return (*this); };
  81. return (operator=((REFGUID) objGuid)); };
  82. const CStringGUID& operator =(REFGUID rGuid) {
  83. m_guid = rGuid; ReCalcFromGuid(); return (*this); };
  84. const CStringGUID& operator =(LPCOLESTR pszGuid) {
  85. m_bValid=FALSE;
  86. if (pszGuid && SUCCEEDED(CLSIDFromString((LPOLESTR) pszGuid,&m_guid))) ReCalcFromGuid();
  87. return (*this); };
  88. const CStringGUID& operator =(LPCSTR pszGuid) {
  89. USES_CONVERSION; return (operator=(pszGuid?A2W(pszGuid):NULL)); };
  90. const CStringGUID& operator =(const VARIANT *pvarGuid) {
  91. if (!pvarGuid) { m_bValid=FALSE; return (*this); } return (operator =(*pvarGuid)); };
  92. const CStringGUID& operator =(const VARIANT& varGuid) {
  93. CComVariant varTmp(varGuid);
  94. if (!SUCCEEDED(varTmp.ChangeType(VT_BSTR))) { m_bValid=FALSE; return (*this); };
  95. return (operator =(varTmp.bstrVal)); };
  96. GUID* operator &() { _ASSERTE(!m_bValid); return (&m_guid); };
  97. BOOL operator !() const { return (!m_bValid); };
  98. private:
  99. BOOL m_bValid;
  100. GUID m_guid;
  101. WCHAR m_szGuidW[40];
  102. CHAR m_szGuidA[40];
  103. };
  104. #endif // __SEOEXPORTS_H__