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.

135 lines
3.4 KiB

  1. #include "shellprv.h"
  2. #include "ftascstr.h"
  3. #include "ftassoc.h" //for now, until use CoCreateInstance
  4. #include "ftenum.h" //for now, until use CoCreateInstance
  5. HRESULT CFTAssocStore::_hresAccess = -1;
  6. HRESULT CFTAssocStore::EnumAssocInfo(ASENUM asenumFlags, LPTSTR pszStr,
  7. AIINIT aiinitFlags, IEnumAssocInfo** ppEnum)
  8. {
  9. //for now
  10. *ppEnum = new CFTEnumAssocInfo();
  11. if (*ppEnum)
  12. {
  13. (*ppEnum)->Init(asenumFlags, pszStr, aiinitFlags);
  14. }
  15. return (*ppEnum) ? S_OK : E_OUTOFMEMORY;
  16. }
  17. HRESULT CFTAssocStore::GetAssocInfo(LPTSTR pszStr, AIINIT aiinitFlags, IAssocInfo** ppAI)
  18. {
  19. HRESULT hres = E_FAIL;
  20. *ppAI = new CFTAssocInfo();
  21. if (*ppAI)
  22. hres = (*ppAI)->Init(aiinitFlags, pszStr);
  23. else
  24. hres = E_OUTOFMEMORY;
  25. return hres;
  26. }
  27. HRESULT CFTAssocStore::GetComplexAssocInfo(LPTSTR pszStr1, AIINIT aiinitFlags1,
  28. LPTSTR pszStr2, AIINIT aiinitFlags2, IAssocInfo** ppAI)
  29. {
  30. HRESULT hres = E_FAIL;
  31. *ppAI = new CFTAssocInfo();
  32. if (*ppAI)
  33. hres = (*ppAI)->InitComplex(aiinitFlags1, pszStr1, aiinitFlags2, pszStr2);
  34. else
  35. hres = E_OUTOFMEMORY;
  36. return hres;
  37. }
  38. HRESULT CFTAssocStore::CheckAccess()
  39. {
  40. if (-1 == _hresAccess)
  41. {
  42. TCHAR szGUID[] = TEXT("{A4BFEC7C-F821-11d2-86BE-0000F8757D7E}");
  43. DWORD dwDisp = 0;
  44. int cTry = 0;
  45. HKEY hkey;
  46. _hresAccess = S_FALSE;
  47. // we want to try this only two times
  48. while ((S_FALSE == _hresAccess) && (cTry <= 1))
  49. {
  50. ++cTry;
  51. // we try to write a GUID to HKCR and delete it
  52. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CLASSES_ROOT, szGUID, 0, NULL, REG_OPTION_NON_VOLATILE,
  53. MAXIMUM_ALLOWED, NULL, &hkey, &dwDisp))
  54. {
  55. // Did we really created a new key?
  56. if (REG_CREATED_NEW_KEY == dwDisp)
  57. {
  58. // yes
  59. RegCloseKey(hkey);
  60. if (ERROR_SUCCESS == RegDeleteKey(HKEY_CLASSES_ROOT, szGUID))
  61. {
  62. _hresAccess = S_OK;
  63. }
  64. }
  65. else
  66. {
  67. // No, there was already one, maybe we crashed right in the middle of this fct
  68. // some other time in the past
  69. // delete the key and try again
  70. RegDeleteKey(HKEY_CLASSES_ROOT, szGUID);
  71. }
  72. }
  73. }
  74. }
  75. return _hresAccess;
  76. }
  77. ///////////////////////////////////////////////////////////////////////////////
  78. //
  79. CFTAssocStore::CFTAssocStore()
  80. {
  81. _hresCoInit = SHCoInitialize();
  82. //DLLAddRef();
  83. }
  84. CFTAssocStore::~CFTAssocStore()
  85. {
  86. //DLLRelease();
  87. SHCoUninitialize(_hresCoInit);
  88. }
  89. //IUnknown methods
  90. HRESULT CFTAssocStore::QueryInterface(REFIID riid, PVOID* ppv)
  91. {
  92. if (IsEqualIID(riid, IID_IUnknown))
  93. *ppv = static_cast<IUnknown*>(this);
  94. else
  95. *ppv = static_cast<IAssocStore*>(this);
  96. return S_OK;
  97. }
  98. ULONG CFTAssocStore::AddRef()
  99. {
  100. return InterlockedIncrement(&_cRef);
  101. }
  102. ULONG CFTAssocStore::Release()
  103. {
  104. ASSERT( 0 != _cRef );
  105. ULONG cRef = InterlockedDecrement(&_cRef);
  106. if ( 0 == cRef )
  107. {
  108. delete this;
  109. }
  110. return cRef;
  111. }