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.

374 lines
8.9 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: WIADEFUI.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/13/1999
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <initguid.h>
  19. #include <shlguid.h>
  20. #include <wiadevdp.h>
  21. #include <itranhlp.h>
  22. #include <isuppfmt.h>
  23. #include "resource.h"
  24. #include "wiauiext.h"
  25. #include "uicommon.h"
  26. #include "apdropt.h"
  27. // DLL reference counters
  28. static LONG g_nServerLocks = 0;
  29. static LONG g_nComponents = 0;
  30. // DLL instance
  31. HINSTANCE g_hInstance;
  32. void DllAddRef()
  33. {
  34. WIA_PUSHFUNCTION(TEXT("DllAddRef"));
  35. InterlockedIncrement(&g_nComponents);
  36. }
  37. void DllRelease()
  38. {
  39. WIA_PUSHFUNCTION(TEXT("DllRelease"));
  40. InterlockedDecrement(&g_nComponents);
  41. }
  42. class CWiaDefaultUiClassFactory : public IClassFactory
  43. {
  44. private:
  45. LONG m_cRef;
  46. public:
  47. // IUnknown
  48. STDMETHODIMP QueryInterface( const IID &iid, void **ppv);
  49. STDMETHODIMP_(ULONG) AddRef(void);
  50. STDMETHODIMP_(ULONG) Release(void);
  51. // IClassFactory
  52. STDMETHODIMP CreateInstance( IUnknown *pUnknownOuter, const IID &iid, void **ppvObject );
  53. STDMETHODIMP LockServer( BOOL bLock );
  54. CWiaDefaultUiClassFactory()
  55. : m_cRef(1)
  56. {
  57. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUiClassFactory::CWiaDefaultUiClassFactory"));
  58. }
  59. ~CWiaDefaultUiClassFactory(void)
  60. {
  61. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUiClassFactory::~CWiaDefaultUiClassFactory"));
  62. }
  63. };
  64. STDMETHODIMP CWiaDefaultUiClassFactory::QueryInterface( const IID &iid, void **ppvObject )
  65. {
  66. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUiClassFactory::QueryInterface"));
  67. if ((iid==IID_IUnknown) || (iid==IID_IClassFactory))
  68. {
  69. *ppvObject = static_cast<LPVOID>(this);
  70. }
  71. else
  72. {
  73. *ppvObject = NULL;
  74. return(E_NOINTERFACE);
  75. }
  76. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  77. return(S_OK);
  78. }
  79. STDMETHODIMP_(ULONG) CWiaDefaultUiClassFactory::AddRef(void)
  80. {
  81. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUiClassFactory::AddRef"));
  82. return(InterlockedIncrement(&m_cRef));
  83. }
  84. STDMETHODIMP_(ULONG) CWiaDefaultUiClassFactory::Release(void)
  85. {
  86. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUiClassFactory::Release"));
  87. if (InterlockedDecrement(&m_cRef)==0)
  88. {
  89. delete this;
  90. return 0;
  91. }
  92. return(m_cRef);
  93. }
  94. STDMETHODIMP CWiaDefaultUiClassFactory::CreateInstance( IUnknown *pUnknownOuter, const IID &iid, void **ppvObject )
  95. {
  96. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUiClassFactory::CreateInstance"));
  97. //
  98. // No aggregation supported
  99. //
  100. if (pUnknownOuter)
  101. {
  102. return(CLASS_E_NOAGGREGATION);
  103. }
  104. CWiaDefaultUI *pWiaUIExtension = new CWiaDefaultUI();
  105. if (!pWiaUIExtension)
  106. {
  107. return(E_OUTOFMEMORY);
  108. }
  109. HRESULT hr = pWiaUIExtension->QueryInterface( iid, ppvObject );
  110. pWiaUIExtension->Release();
  111. return (hr);
  112. }
  113. STDMETHODIMP CWiaDefaultUiClassFactory::LockServer(BOOL bLock)
  114. {
  115. WIA_PUSHFUNCTION(TEXT("CWiaDefaultUiClassFactory::LockServer"));
  116. if (bLock)
  117. {
  118. InterlockedIncrement(&g_nServerLocks);
  119. }
  120. else
  121. {
  122. InterlockedDecrement(&g_nServerLocks);
  123. }
  124. return(S_OK);
  125. }
  126. class CWiaAutoPlayDropTargetClassFactory : public IClassFactory
  127. {
  128. private:
  129. LONG m_cRef;
  130. public:
  131. // IUnknown
  132. STDMETHODIMP QueryInterface( const IID &iid, void **ppv);
  133. STDMETHODIMP_(ULONG) AddRef(void);
  134. STDMETHODIMP_(ULONG) Release(void);
  135. // IClassFactory
  136. STDMETHODIMP CreateInstance( IUnknown *pUnknownOuter, const IID &iid, void **ppvObject );
  137. STDMETHODIMP LockServer( BOOL bLock );
  138. CWiaAutoPlayDropTargetClassFactory()
  139. : m_cRef(1)
  140. {
  141. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTargetClassFactory::CWiaAutoPlayDropTargetClassFactory"));
  142. }
  143. ~CWiaAutoPlayDropTargetClassFactory(void)
  144. {
  145. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTargetClassFactory::~CWiaAutoPlayDropTargetClassFactory"));
  146. }
  147. };
  148. STDMETHODIMP CWiaAutoPlayDropTargetClassFactory::QueryInterface( const IID &iid, void **ppvObject )
  149. {
  150. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTargetClassFactory::QueryInterface"));
  151. if ((iid==IID_IUnknown) || (iid==IID_IClassFactory))
  152. {
  153. *ppvObject = static_cast<LPVOID>(this);
  154. }
  155. else
  156. {
  157. *ppvObject = NULL;
  158. return(E_NOINTERFACE);
  159. }
  160. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  161. return(S_OK);
  162. }
  163. STDMETHODIMP_(ULONG) CWiaAutoPlayDropTargetClassFactory::AddRef(void)
  164. {
  165. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTargetClassFactory::AddRef"));
  166. return(InterlockedIncrement(&m_cRef));
  167. }
  168. STDMETHODIMP_(ULONG) CWiaAutoPlayDropTargetClassFactory::Release(void)
  169. {
  170. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTargetClassFactory::Release"));
  171. if (InterlockedDecrement(&m_cRef)==0)
  172. {
  173. delete this;
  174. return 0;
  175. }
  176. return(m_cRef);
  177. }
  178. STDMETHODIMP CWiaAutoPlayDropTargetClassFactory::CreateInstance( IUnknown *pUnknownOuter, const IID &iid, void **ppvObject )
  179. {
  180. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTargetClassFactory::CreateInstance"));
  181. //
  182. // No aggregation supported
  183. //
  184. if (pUnknownOuter)
  185. {
  186. return(CLASS_E_NOAGGREGATION);
  187. }
  188. CWiaAutoPlayDropTarget *pWiaAutoPlayDropTarget = new CWiaAutoPlayDropTarget();
  189. if (!pWiaAutoPlayDropTarget)
  190. {
  191. return(E_OUTOFMEMORY);
  192. }
  193. HRESULT hr = pWiaAutoPlayDropTarget->QueryInterface( iid, ppvObject );
  194. pWiaAutoPlayDropTarget->Release();
  195. return (hr);
  196. }
  197. STDMETHODIMP CWiaAutoPlayDropTargetClassFactory::LockServer(BOOL bLock)
  198. {
  199. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTargetClassFactory::LockServer"));
  200. if (bLock)
  201. {
  202. InterlockedIncrement(&g_nServerLocks);
  203. }
  204. else
  205. {
  206. InterlockedDecrement(&g_nServerLocks);
  207. }
  208. return(S_OK);
  209. }
  210. extern "C" BOOL WINAPI DllMain( HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved )
  211. {
  212. switch (dwReason)
  213. {
  214. case DLL_PROCESS_ATTACH:
  215. SHFusionInitializeFromModuleID( hinst, 123 );
  216. g_hInstance = hinst;
  217. DisableThreadLibraryCalls(hinst);
  218. WIA_DEBUG_CREATE(hinst);
  219. break;
  220. case DLL_PROCESS_DETACH:
  221. SHFusionUninitialize();
  222. WIA_REPORT_LEAKS();
  223. WIA_DEBUG_DESTROY();
  224. break;
  225. }
  226. return(TRUE);
  227. }
  228. extern "C" STDMETHODIMP DllRegisterServer(void)
  229. {
  230. return WiaUiUtil::InstallInfFromResource( g_hInstance, "RegDllCommon" );
  231. }
  232. extern "C" STDMETHODIMP DllUnregisterServer(void)
  233. {
  234. return WiaUiUtil::InstallInfFromResource( g_hInstance, "UnregDllCommon" );
  235. }
  236. extern "C" STDMETHODIMP DllCanUnloadNow(void)
  237. {
  238. WIA_PUSHFUNCTION(TEXT("DllCanUnloadNow"));
  239. if (g_nServerLocks == 0 && g_nComponents == 0)
  240. {
  241. WIA_TRACE((TEXT("Can unload")));
  242. return S_OK;
  243. }
  244. else
  245. {
  246. WIA_ERROR((TEXT("Can't unload module!")));
  247. return S_FALSE;
  248. }
  249. }
  250. extern "C" STDAPI DllGetClassObject( const CLSID &clsid, const IID &iid, void **ppvObject )
  251. {
  252. WIA_PUSHFUNCTION(TEXT("DllGetClassObject"));
  253. HRESULT hr = E_FAIL;
  254. //
  255. // Make sure we've got a valid ppvObject
  256. //
  257. if (!ppvObject)
  258. {
  259. return(E_INVALIDARG);
  260. }
  261. //
  262. // Make sure this component is supplied by this server
  263. //
  264. if (CLSID_WiaDefaultUi == clsid)
  265. {
  266. //
  267. // Create class factory
  268. //
  269. CWiaDefaultUiClassFactory *pWiaDefaultUiClassFactory = new CWiaDefaultUiClassFactory;
  270. if (pWiaDefaultUiClassFactory)
  271. {
  272. //
  273. // Get the requested interface
  274. //
  275. hr = pWiaDefaultUiClassFactory->QueryInterface( iid, ppvObject );
  276. //
  277. // Release the 'new-ed' instance
  278. //
  279. pWiaDefaultUiClassFactory->Release();
  280. }
  281. else
  282. {
  283. hr = E_OUTOFMEMORY;
  284. }
  285. }
  286. else if (CLSID_WiaAutoPlayDropTarget == clsid)
  287. {
  288. //
  289. // Create class factory
  290. //
  291. CWiaAutoPlayDropTargetClassFactory *pWiaAutoPlayDropTargetClassFactory = new CWiaAutoPlayDropTargetClassFactory;
  292. if (pWiaAutoPlayDropTargetClassFactory)
  293. {
  294. //
  295. // Get the requested interface
  296. //
  297. hr = pWiaAutoPlayDropTargetClassFactory->QueryInterface( iid, ppvObject );
  298. //
  299. // Release the 'new-ed' instance
  300. //
  301. pWiaAutoPlayDropTargetClassFactory->Release();
  302. }
  303. else
  304. {
  305. hr = E_OUTOFMEMORY;
  306. }
  307. }
  308. else
  309. {
  310. hr = CLASS_E_CLASSNOTAVAILABLE;
  311. }
  312. return (hr);
  313. }