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.

437 lines
10 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: wiacam.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 16 July, 2000
  10. *
  11. * DESCRIPTION:
  12. * Implementation of the WIA Sample camera class factory and IUNKNOWN interface.
  13. *
  14. *******************************************************************************/
  15. #include "pch.h"
  16. #ifndef INITGUID
  17. #include <initguid.h>
  18. #endif
  19. #if !defined(dllexp)
  20. #define DLLEXPORT __declspec( dllexport )
  21. #endif
  22. HINSTANCE g_hInst; // DLL module instance.
  23. //
  24. // This clsid will eventually be in uuid.lib, at which point it should be removed
  25. // from here.
  26. //
  27. // {0C9BB460-51AC-11D0-90EA-00AA0060F86C}
  28. DEFINE_GUID(IID_IStiUSD, 0x0C9BB460L, 0x51AC, 0x11D0, 0x90, 0xEA, 0x00, 0xAA, 0x00, 0x60, 0xF8, 0x6C);
  29. //
  30. // Class ID for this WIA minidriver. Change this GUID here and in the
  31. // INF for your driver.
  32. //
  33. DEFINE_GUID(CLSID_SampleWIACameraDevice,
  34. 0x8e3f2bae, 0xc8ff, 0x4eff, 0xaa, 0xbd, 0xc, 0x58, 0x69, 0x53, 0x89, 0xe8);
  35. /**************************************************************************\
  36. * CWiaCameraDeviceClassFactory::CWiaCameraDeviceClassFactory(void)
  37. *
  38. *
  39. *
  40. * Arguments:
  41. *
  42. * None
  43. *
  44. \**************************************************************************/
  45. CWiaCameraDeviceClassFactory::CWiaCameraDeviceClassFactory(void)
  46. {
  47. // Constructor logic
  48. m_cRef = 0;
  49. }
  50. /**************************************************************************\
  51. * CWiaCameraDeviceClassFactory::~CWiaCameraDeviceClassFactory(void)
  52. *
  53. *
  54. *
  55. * Arguments:
  56. *
  57. * None
  58. *
  59. \**************************************************************************/
  60. CWiaCameraDeviceClassFactory::~CWiaCameraDeviceClassFactory(void)
  61. {
  62. // Destructor logic
  63. }
  64. /**************************************************************************\
  65. * CWiaCameraDeviceClassFactory::QueryInterface
  66. *
  67. *
  68. *
  69. * Arguments:
  70. *
  71. * riid -
  72. * ppvObject -
  73. *
  74. \**************************************************************************/
  75. STDMETHODIMP CWiaCameraDeviceClassFactory::QueryInterface(
  76. REFIID riid,
  77. void __RPC_FAR *__RPC_FAR *ppvObject)
  78. {
  79. *ppvObject = NULL;
  80. if (IsEqualIID(riid, IID_IUnknown) ||
  81. IsEqualIID(riid, IID_IClassFactory)) {
  82. *ppvObject = (LPVOID)this;
  83. AddRef();
  84. return NOERROR;
  85. }
  86. return ResultFromScode(E_NOINTERFACE);
  87. }
  88. /**************************************************************************\
  89. * CWiaCameraDeviceClassFactory::AddRef
  90. *
  91. *
  92. *
  93. * Arguments:
  94. *
  95. * None
  96. *
  97. \**************************************************************************/
  98. STDMETHODIMP_(ULONG) CWiaCameraDeviceClassFactory::AddRef(void)
  99. {
  100. return InterlockedIncrement((LPLONG)&m_cRef);
  101. }
  102. /**************************************************************************\
  103. * CWiaCameraDeviceClassFactory::Release
  104. *
  105. *
  106. *
  107. * Arguments:
  108. *
  109. * None
  110. *
  111. \**************************************************************************/
  112. STDMETHODIMP_(ULONG) CWiaCameraDeviceClassFactory::Release(void)
  113. {
  114. ULONG ulRef = 0;
  115. ulRef = InterlockedDecrement((LPLONG)&m_cRef);
  116. if (!ulRef) {
  117. delete this;
  118. }
  119. return ulRef;
  120. }
  121. /**************************************************************************\
  122. * CWiaCameraDeviceClassFactory::CreateInstance
  123. *
  124. *
  125. *
  126. * Arguments:
  127. *
  128. * punkOuter -
  129. * riid, -
  130. * ppvObject -
  131. *
  132. \**************************************************************************/
  133. STDMETHODIMP CWiaCameraDeviceClassFactory::CreateInstance(
  134. IUnknown __RPC_FAR *punkOuter,
  135. REFIID riid,
  136. void __RPC_FAR *__RPC_FAR *ppvObject)
  137. {
  138. if (!IsEqualIID(riid, IID_IStiUSD) &&
  139. !IsEqualIID(riid, IID_IUnknown)) {
  140. return STIERR_NOINTERFACE;
  141. }
  142. // When created for aggregation, only IUnknown can be requested.
  143. if (punkOuter && !IsEqualIID(riid, IID_IUnknown)) {
  144. return CLASS_E_NOAGGREGATION;
  145. }
  146. HRESULT hr = S_OK;
  147. CWiaCameraDevice *pDev = NULL;
  148. pDev = new CWiaCameraDevice(punkOuter);
  149. if (!pDev) {
  150. return STIERR_OUTOFMEMORY;
  151. }
  152. // Move to the requested interface if we aren't aggregated.
  153. // Don't do this if aggregated, or we will lose the private
  154. // IUnknown and then the caller will be hosed.
  155. hr = pDev->NonDelegatingQueryInterface(riid,ppvObject);
  156. pDev->NonDelegatingRelease();
  157. return hr;
  158. }
  159. /**************************************************************************\
  160. * CWiaCameraDeviceClassFactory::LockServer
  161. *
  162. *
  163. *
  164. * Arguments:
  165. *
  166. * None
  167. *
  168. \**************************************************************************/
  169. STDMETHODIMP CWiaCameraDeviceClassFactory::LockServer(BOOL fLock)
  170. {
  171. return NOERROR;
  172. }
  173. /**************************************************************************\
  174. * CWiaCameraDevice::NonDelegatingQueryInterface
  175. *
  176. *
  177. *
  178. * Arguments:
  179. *
  180. * None
  181. *
  182. \**************************************************************************/
  183. STDMETHODIMP CWiaCameraDevice::NonDelegatingQueryInterface(
  184. REFIID riid,
  185. LPVOID *ppvObj)
  186. {
  187. HRESULT hr = S_OK;
  188. if (!ppvObj) {
  189. return STIERR_INVALID_PARAM;
  190. }
  191. *ppvObj = NULL;
  192. if (IsEqualIID( riid, IID_IUnknown )) {
  193. *ppvObj = static_cast<INonDelegatingUnknown*>(this);
  194. }
  195. else if (IsEqualIID( riid, IID_IStiUSD )) {
  196. *ppvObj = static_cast<IStiUSD*>(this);
  197. }
  198. else if (IsEqualIID( riid, IID_IWiaMiniDrv )) {
  199. *ppvObj = static_cast<IWiaMiniDrv*>(this);
  200. }
  201. else {
  202. hr = STIERR_NOINTERFACE;
  203. }
  204. if (SUCCEEDED(hr)) {
  205. (reinterpret_cast<IUnknown*>(*ppvObj))->AddRef();
  206. }
  207. return hr;
  208. }
  209. /**************************************************************************\
  210. * CWiaCameraDevice::NonDelegatingAddRef
  211. *
  212. *
  213. *
  214. * Arguments:
  215. *
  216. * None
  217. *
  218. \**************************************************************************/
  219. STDMETHODIMP_(ULONG) CWiaCameraDevice::NonDelegatingAddRef(void)
  220. {
  221. return InterlockedIncrement((LPLONG)&m_cRef);
  222. }
  223. /**************************************************************************\
  224. * CWiaCameraDevice::NonDelegatingRelease
  225. *
  226. *
  227. *
  228. * Arguments:
  229. *
  230. * None
  231. *
  232. \**************************************************************************/
  233. STDMETHODIMP_(ULONG) CWiaCameraDevice::NonDelegatingRelease(void)
  234. {
  235. ULONG ulRef = 0;
  236. ulRef = InterlockedDecrement((LPLONG)&m_cRef);
  237. if (!ulRef) {
  238. delete this;
  239. }
  240. return ulRef;
  241. }
  242. /**************************************************************************\
  243. * CWiaCameraDevice::QueryInterface
  244. *
  245. *
  246. *
  247. * Arguments:
  248. *
  249. * None
  250. *
  251. \**************************************************************************/
  252. STDMETHODIMP CWiaCameraDevice::QueryInterface(REFIID riid, LPVOID* ppvObj)
  253. {
  254. return m_punkOuter->QueryInterface(riid,ppvObj);
  255. }
  256. /**************************************************************************\
  257. * CWiaCameraDevice::AddRef
  258. *
  259. *
  260. *
  261. * Arguments:
  262. *
  263. * None
  264. *
  265. \**************************************************************************/
  266. STDMETHODIMP_(ULONG) CWiaCameraDevice::AddRef(void)
  267. {
  268. return m_punkOuter->AddRef();
  269. }
  270. /**************************************************************************\
  271. * CWiaCameraDevice::Release
  272. *
  273. *
  274. *
  275. * Arguments:
  276. *
  277. * None
  278. *
  279. \**************************************************************************/
  280. STDMETHODIMP_(ULONG) CWiaCameraDevice::Release(void)
  281. {
  282. return m_punkOuter->Release();
  283. }
  284. /**************************************************************************\
  285. * DllEntryPoint
  286. *
  287. * Main library entry point. Receives DLL event notification from OS.
  288. *
  289. * We are not interested in thread attaches and detaches,
  290. * so we disable thread notifications for performance reasons.
  291. *
  292. * Arguments:
  293. *
  294. * hinst -
  295. * dwReason -
  296. * lpReserved -
  297. *
  298. * Return Value:
  299. *
  300. * Returns TRUE to allow the DLL to load.
  301. *
  302. \**************************************************************************/
  303. extern "C" DLLEXPORT BOOL APIENTRY DllEntryPoint(
  304. HINSTANCE hinst,
  305. DWORD dwReason,
  306. LPVOID lpReserved)
  307. {
  308. switch (dwReason) {
  309. case DLL_PROCESS_ATTACH:
  310. g_hInst = hinst;
  311. DisableThreadLibraryCalls(hinst);
  312. break;
  313. case DLL_PROCESS_DETACH:
  314. break;
  315. }
  316. return TRUE;
  317. }
  318. /**************************************************************************\
  319. * DllCanUnloadNow
  320. *
  321. * Determines whether the DLL has any outstanding interfaces.
  322. *
  323. * Arguments:
  324. *
  325. * None
  326. *
  327. * Return Value:
  328. *
  329. * Returns S_OK if the DLL can unload, S_FALSE if it is not safe to unload.
  330. *
  331. \**************************************************************************/
  332. extern "C" STDMETHODIMP DllCanUnloadNow(void)
  333. {
  334. return S_OK;
  335. }
  336. /**************************************************************************\
  337. * DllGetClassObject
  338. *
  339. * Create an IClassFactory instance for this DLL. We support only one
  340. * class of objects, so this function does not need to go through a table
  341. * of supported classes, looking for the proper constructor.
  342. *
  343. * Arguments:
  344. *
  345. * rclsid - The object being requested.
  346. * riid - The desired interface on the object.
  347. * ppv - Output pointer to object.
  348. *
  349. \**************************************************************************/
  350. extern "C" STDAPI DllGetClassObject(
  351. REFCLSID rclsid,
  352. REFIID riid,
  353. LPVOID *ppv)
  354. {
  355. if (!ppv) {
  356. return E_INVALIDARG;
  357. }
  358. *ppv = NULL;
  359. if (!IsEqualCLSID(rclsid, CLSID_SampleWIACameraDevice) ) {
  360. return CLASS_E_CLASSNOTAVAILABLE;
  361. }
  362. if (!IsEqualIID(riid, IID_IUnknown) &&
  363. !IsEqualIID(riid, IID_IClassFactory)) {
  364. return E_NOINTERFACE;
  365. }
  366. if (IsEqualCLSID(rclsid, CLSID_SampleWIACameraDevice)) {
  367. CWiaCameraDeviceClassFactory *pcf = new CWiaCameraDeviceClassFactory;
  368. if (!pcf) {
  369. return E_OUTOFMEMORY;
  370. }
  371. *ppv = (LPVOID)pcf;
  372. }
  373. return S_OK;
  374. }