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.

191 lines
5.0 KiB

  1. #include "pch.h"
  2. #include <advpub.h>
  3. #include "thisdll.h"
  4. #include <cguid.h>
  5. #define DECL_CRTFREE
  6. #include <crtfree.h>
  7. #define DECLARE_DEBUG
  8. #define SZ_DEBUGINI "ccshell.ini"
  9. #define SZ_DEBUGSECTION "Media Handlers"
  10. #define SZ_MODULE "SHMEDIA.DLL"
  11. #include <debug.h>
  12. HINSTANCE m_hInst = NULL;
  13. LONG g_cRefThisDll = 0;
  14. STDAPI_(BOOL) DllMain(HINSTANCE hDll, DWORD dwReason, void *lpRes)
  15. {
  16. switch(dwReason)
  17. {
  18. case DLL_PROCESS_ATTACH:
  19. m_hInst = hDll;
  20. break;
  21. }
  22. return TRUE;
  23. }
  24. STDAPI DllCanUnloadNow(void)
  25. {
  26. return g_cRefThisDll ? S_FALSE : S_OK;
  27. }
  28. // Call ADVPACK for the given section of our resource based INF>
  29. // hInstance = resource instance to get REGINST section from
  30. // szSection = section name to invoke
  31. HRESULT CallRegInstall(HINSTANCE hInstance, LPCSTR szSection)
  32. {
  33. HRESULT hr = E_FAIL;
  34. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  35. if (hinstAdvPack)
  36. {
  37. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  38. if (pfnri)
  39. {
  40. STRENTRY seReg[] =
  41. {
  42. { "25", "%SystemRoot%" },
  43. { "11", "%SystemRoot%\\system32" },
  44. };
  45. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  46. hr = pfnri(hInstance, szSection, &stReg);
  47. }
  48. FreeLibrary(hinstAdvPack);
  49. }
  50. return hr;
  51. }
  52. STDAPI DllRegisterServer(void)
  53. {
  54. CallRegInstall(m_hInst, "RegDll");
  55. return S_OK;
  56. }
  57. STDAPI DllUnregisterServer(void)
  58. {
  59. CallRegInstall(m_hInst, "UnregDll");
  60. return S_OK;
  61. }
  62. CF_TABLE_BEGIN(g_ObjectInfo)
  63. CF_TABLE_ENTRY(&CLSID_AudioMediaProperties, CWMAPropSetStg_CreateInstance, COCREATEONLY),
  64. CF_TABLE_ENTRY(&CLSID_VideoMediaProperties, CWMVPropSetStg_CreateInstance, COCREATEONLY),
  65. CF_TABLE_ENTRY(&CLSID_AVAviProperties, CAviPropSetStg_CreateInstance, COCREATEONLY),
  66. CF_TABLE_ENTRY(&CLSID_AVMidiProperties, CMidiPropSetStg_CreateInstance, COCREATEONLY),
  67. CF_TABLE_ENTRY(&CLSID_AVWavProperties, CWavPropSetStg_CreateInstance, COCREATEONLY),
  68. CF_TABLE_ENTRY(&CLSID_VideoThumbnail, CVideoThumbnail_CreateInstance, COCREATEONLY),
  69. CF_TABLE_END(g_ObjectInfo)
  70. // constructor for CObjectInfo.
  71. CObjectInfo::CObjectInfo(CLSID const* pclsidin, LPFNCREATEOBJINSTANCE pfnCreatein, IID const* piidIn,
  72. IID const* piidEventsIn, long lVersionIn, DWORD dwOleMiscFlagsIn,
  73. DWORD dwClassFactFlagsIn)
  74. {
  75. pclsid = pclsidin;
  76. pfnCreateInstance = pfnCreatein;
  77. piid = piidIn;
  78. piidEvents = piidEventsIn;
  79. lVersion = lVersionIn;
  80. dwOleMiscFlags = dwOleMiscFlagsIn;
  81. dwClassFactFlags = dwClassFactFlagsIn;
  82. }
  83. // static class factory (no allocs!)
  84. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  85. {
  86. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  87. {
  88. *ppvObj = (void *)GET_ICLASSFACTORY(this);
  89. DllAddRef();
  90. return S_OK;
  91. }
  92. *ppvObj = NULL;
  93. return E_NOINTERFACE;
  94. }
  95. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  96. {
  97. DllAddRef();
  98. return 2;
  99. }
  100. STDMETHODIMP_(ULONG) CClassFactory::Release()
  101. {
  102. DllRelease();
  103. return 1;
  104. }
  105. STDMETHODIMP CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  106. {
  107. *ppv = NULL;
  108. if (punkOuter && !IsEqualIID(riid, IID_IUnknown))
  109. {
  110. // It is technically illegal to aggregate an object and request
  111. // any interface other than IUnknown. Enforce this.
  112. //
  113. return CLASS_E_NOAGGREGATION;
  114. }
  115. else
  116. {
  117. LPOBJECTINFO pthisobj = (LPOBJECTINFO)this;
  118. if (punkOuter && !(pthisobj->dwClassFactFlags & OIF_ALLOWAGGREGATION))
  119. return CLASS_E_NOAGGREGATION;
  120. IUnknown *punk;
  121. HRESULT hr = pthisobj->pfnCreateInstance(punkOuter, &punk, pthisobj);
  122. if (SUCCEEDED(hr))
  123. {
  124. hr = punk->QueryInterface(riid, ppv);
  125. punk->Release();
  126. }
  127. return hr;
  128. }
  129. }
  130. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  131. {
  132. if (fLock)
  133. DllAddRef();
  134. else
  135. DllRelease();
  136. return S_OK;
  137. }
  138. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  139. {
  140. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  141. {
  142. for (LPCOBJECTINFO pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  143. {
  144. if (IsEqualGUID(rclsid, *(pcls->pclsid)))
  145. {
  146. *ppv = (void*)pcls;
  147. DllAddRef(); // class factory holds DLL ref count
  148. return S_OK;
  149. }
  150. }
  151. }
  152. *ppv = NULL;
  153. return CLASS_E_CLASSNOTAVAILABLE;
  154. }
  155. STDAPI_(void) DllAddRef(void)
  156. {
  157. InterlockedIncrement(&g_cRefThisDll);
  158. }
  159. STDAPI_(void) DllRelease(void)
  160. {
  161. ASSERT( 0 != g_cRefThisDll );
  162. InterlockedDecrement(&g_cRefThisDll);
  163. }