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.

116 lines
3.4 KiB

  1. //
  2. // This file contains the implementation of SHCreateDefClassObject
  3. //
  4. #include "shellprv.h"
  5. #pragma hdrstop
  6. typedef struct
  7. {
  8. IClassFactory cf;
  9. UINT cRef; // Reference count
  10. DWORD dwFlags; // Flags to control creation...
  11. LPFNCREATEINSTANCE pfnCreateInstance; // CreateInstance callback entry
  12. UINT * pcRefDll; // Reference count of the DLL
  13. } CClassFactory;
  14. STDMETHODIMP CClassFactory_QueryInterface(IClassFactory *pcf, REFIID riid, void **ppvObj)
  15. {
  16. CClassFactory *this = IToClass(CClassFactory, cf, pcf);
  17. if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
  18. {
  19. InterlockedIncrement(&this->cRef);
  20. *ppvObj = (LPVOID) (IClassFactory *) &this->cf;
  21. return NOERROR;
  22. }
  23. *ppvObj = NULL;
  24. return E_NOINTERFACE;
  25. }
  26. STDMETHODIMP_(ULONG) CClassFactory_AddRef(IClassFactory *pcf)
  27. {
  28. CClassFactory *this = IToClass(CClassFactory, cf, pcf);
  29. return this->cRef;
  30. }
  31. STDMETHODIMP_(ULONG) CClassFactory_Release(IClassFactory *pcf)
  32. {
  33. CClassFactory *this = IToClass(CClassFactory, cf, pcf);
  34. if (--this->cRef > 0)
  35. return this->cRef;
  36. LocalFree((HLOCAL)this);
  37. return 0;
  38. }
  39. STDMETHODIMP CClassFactory_CreateInstance(IClassFactory *pcf, IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
  40. {
  41. CClassFactory *this = IToClass(CClassFactory, cf, pcf);
  42. *ppvObject = NULL;
  43. if (pUnkOuter)
  44. return CLASS_E_NOAGGREGATION;
  45. return this->pfnCreateInstance(pUnkOuter, riid, ppvObject);
  46. }
  47. STDMETHODIMP CClassFactory_LockServer(IClassFactory *pcf, BOOL fLock)
  48. {
  49. CClassFactory *this = IToClass(CClassFactory, cf, pcf);
  50. if (this->pcRefDll)
  51. {
  52. if (fLock)
  53. this->pcRefDll++;
  54. else
  55. this->pcRefDll--;
  56. }
  57. return S_OK;
  58. }
  59. const IClassFactoryVtbl c_vtblAppUIClassFactory = {
  60. CClassFactory_QueryInterface, CClassFactory_AddRef, CClassFactory_Release,
  61. CClassFactory_CreateInstance,
  62. CClassFactory_LockServer
  63. };
  64. //
  65. // creates a simple default implementation of IClassFactory
  66. //
  67. // Parameters:
  68. // riid -- Specifies the interface to the class object
  69. // ppv -- Specifies the pointer to LPVOID where the class object pointer
  70. // will be returned.
  71. // pfnCreateInstance -- Specifies the callback entry for instanciation.
  72. // pcRefDll -- Specifies the address to the DLL reference count (optional)
  73. //
  74. // Notes:
  75. // The riidInst will be specified only if the instance of the class
  76. // support only one interface.
  77. //
  78. // we would like to get rid of this
  79. // this API called by MMSYS.CPL, RNAUI.DLL, SYNCUI.DLL
  80. STDAPI SHCreateDefClassObject(REFIID riid, void **ppv, LPFNCREATEINSTANCE pfnCreateInstance, UINT *pcRefDll, REFIID riidInst)
  81. {
  82. *ppv = NULL;
  83. if (IsEqualIID(riid, &IID_IClassFactory))
  84. {
  85. CClassFactory *pacf = (CClassFactory *)LocalAlloc(LPTR, SIZEOF(CClassFactory));
  86. if (pacf)
  87. {
  88. pacf->cf.lpVtbl = &c_vtblAppUIClassFactory;
  89. pacf->cRef++; // pacf->cRef=0; (generates smaller code)
  90. pacf->pcRefDll = pcRefDll;
  91. pacf->pfnCreateInstance = pfnCreateInstance;
  92. (IClassFactory *)*ppv = &pacf->cf;
  93. return NOERROR;
  94. }
  95. return E_OUTOFMEMORY;
  96. }
  97. return E_NOINTERFACE;
  98. }