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.

105 lines
1.7 KiB

  1. #include <windows.h>
  2. #include <objbase.h>
  3. #include <shlobj.h>
  4. #include <docobj.h>
  5. #include "shfolder.h"
  6. #include "classfac.h"
  7. extern LONG g_DllRefCount;
  8. CClassFactory::CClassFactory()
  9. {
  10. m_ObjRefCount = 1;
  11. InterlockedIncrement(&g_DllRefCount);
  12. }
  13. CClassFactory::~CClassFactory()
  14. {
  15. InterlockedDecrement(&g_DllRefCount);
  16. }
  17. STDMETHODIMP
  18. CClassFactory::QueryInterface(
  19. REFIID riid,
  20. LPVOID *ppReturn
  21. )
  22. {
  23. *ppReturn = NULL;
  24. if(IsEqualIID(riid, IID_IUnknown))
  25. *ppReturn = (IUnknown*)(CClassFactory*)this;
  26. else if(IsEqualIID(riid, IID_IClassFactory))
  27. *ppReturn = (CClassFactory*)this;
  28. if(*ppReturn == NULL)
  29. return E_NOINTERFACE;
  30. (*(LPUNKNOWN*)ppReturn)->AddRef();
  31. return S_OK;
  32. }
  33. STDMETHODIMP_(DWORD)
  34. CClassFactory::AddRef()
  35. {
  36. return InterlockedIncrement(&m_ObjRefCount);
  37. }
  38. STDMETHODIMP_(DWORD)
  39. CClassFactory::Release()
  40. {
  41. LONG lDecremented = InterlockedDecrement(&m_ObjRefCount);
  42. if(lDecremented == 0)
  43. delete this;
  44. return lDecremented;
  45. }
  46. STDMETHODIMP
  47. CClassFactory::CreateInstance(
  48. LPUNKNOWN pUnknown,
  49. REFIID riid,
  50. LPVOID *ppObject
  51. )
  52. {
  53. if(pUnknown != NULL)
  54. return CLASS_E_NOAGGREGATION;
  55. CShellFolder *pShellFolder = new CShellFolder(NULL, NULL);
  56. if(NULL == pShellFolder)
  57. return E_OUTOFMEMORY;
  58. //
  59. // get the QueryInterface return for our return value
  60. //
  61. HRESULT hResult = pShellFolder->QueryInterface(riid, ppObject);
  62. //
  63. // call Release to decrement the ref count
  64. //
  65. pShellFolder->Release();
  66. return hResult;
  67. }
  68. STDMETHODIMP
  69. CClassFactory::LockServer(
  70. BOOL fLock
  71. )
  72. {
  73. return E_NOTIMPL;
  74. }