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.

495 lines
9.9 KiB

  1. /*++
  2. Copyright (c) 1996-2002 Microsoft Corp. & Ricoh Co., Ltd. All rights reserved.
  3. FILE: COMOEM.CPP
  4. Abstract: Necessary COM class definition to Unidrv OEM UI plugin module.
  5. Environment: Windows NT Unidrv5 driver
  6. Revision History:
  7. 04/24/1998 -takashim-
  8. Written the original sample so that it is more C++.
  9. 04/22/1999 -Masatoshi Kubokura-
  10. Last modified for Windows2000.
  11. 10/05/2000 -Masatoshi Kubokura-
  12. Last modified for XP inbox.
  13. 03/01/2002 -Masatoshi Kubokura-
  14. Include strsafe.h.
  15. 03/29/2002 -Masatoshi Kubokura-
  16. Eliminate "#if 0".
  17. Change return value from E_FAIL to S_FALSE at DllCanUnloadNow().
  18. --*/
  19. #define INITGUID // for GUID one-time initialization
  20. #include "pdev.h"
  21. #include "names.h"
  22. #ifndef WINNT_40
  23. #include "strsafe.h" // @Mar/01/2002
  24. #endif // !WINNT_40
  25. // Globals
  26. static HMODULE g_hModule = NULL ; // DLL module handle
  27. static long g_cComponents = 0 ; // Count of active components
  28. static long g_cServerLocks = 0 ; // Count of locks
  29. //
  30. // IOemCB Definition
  31. //
  32. class IOemCB : public IPrintOemUI
  33. {
  34. public:
  35. //
  36. // IUnknown methods
  37. //
  38. STDMETHODIMP
  39. QueryInterface(
  40. const IID& iid, void** ppv)
  41. {
  42. VERBOSE((DLLTEXT("IOemCB: QueryInterface entry\n")));
  43. // @Mar/29/2002 ->
  44. if (NULL == ppv)
  45. return E_FAIL;
  46. // @Mar/29/2002 <-
  47. if (iid == IID_IUnknown)
  48. {
  49. *ppv = static_cast<IUnknown*>(this);
  50. VERBOSE((DLLTEXT("IOemCB:Return pointer to IUnknown.\n")));
  51. }
  52. else if (iid == IID_IPrintOemUI)
  53. {
  54. *ppv = static_cast<IPrintOemUI*>(this);
  55. VERBOSE((DLLTEXT("IOemCB:Return pointer to IPrintOemUI.\n")));
  56. }
  57. else
  58. {
  59. *ppv = NULL ;
  60. VERBOSE((DLLTEXT("IOemCB:Return NULL.\n")));
  61. return E_NOINTERFACE ;
  62. }
  63. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  64. return S_OK ;
  65. }
  66. STDMETHODIMP_(ULONG)
  67. AddRef()
  68. {
  69. VERBOSE((DLLTEXT("IOemCB::AddRef() entry.\n")));
  70. return InterlockedIncrement(&m_cRef);
  71. }
  72. STDMETHODIMP_(ULONG)
  73. Release()
  74. {
  75. VERBOSE((DLLTEXT("IOemCB::Release() entry.\n")));
  76. if (InterlockedDecrement(&m_cRef) == 0)
  77. {
  78. delete this ;
  79. return 0 ;
  80. }
  81. return m_cRef ;
  82. }
  83. //
  84. // IPrintOemCommon methods
  85. //
  86. // Function Name: GetInfo
  87. // Plug-in: Any
  88. // Driver: Any
  89. // Type: Mandatory
  90. //
  91. STDMETHODIMP
  92. GetInfo(
  93. DWORD dwMode,
  94. PVOID pBuffer,
  95. DWORD cbSize,
  96. PDWORD pcbNeeded)
  97. {
  98. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  99. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  100. return S_OK;
  101. else
  102. return E_FAIL;
  103. }
  104. //
  105. // Function Name: DevMode
  106. // Plug-in: Rendering module
  107. // Driver: Any
  108. // Type: Optional
  109. //
  110. STDMETHODIMP
  111. DevMode(
  112. DWORD dwMode,
  113. POEMDMPARAM pOemDMParam)
  114. {
  115. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  116. if (OEMDevMode(dwMode, pOemDMParam))
  117. return S_OK;
  118. else
  119. return E_FAIL;
  120. }
  121. //
  122. // IPrintOemUI methods
  123. //
  124. //
  125. // Method for publishing Driver interface.
  126. //
  127. STDMETHODIMP
  128. PublishDriverInterface(
  129. IUnknown *pIUnknown)
  130. {
  131. VERBOSE((DLLTEXT("IOemCB::PublishDriverInterface() entry.\n")));
  132. return S_OK;
  133. }
  134. //
  135. // CommonUIProp
  136. //
  137. STDMETHODIMP
  138. CommonUIProp(
  139. DWORD dwMode,
  140. POEMCUIPPARAM pOemCUIPParam)
  141. {
  142. if (OEMCommonUIProp(dwMode, pOemCUIPParam))
  143. return S_OK;
  144. else
  145. return E_FAIL;
  146. }
  147. //
  148. // DocumentPropertySheets
  149. //
  150. STDMETHODIMP
  151. DocumentPropertySheets(
  152. PPROPSHEETUI_INFO pPSUIInfo,
  153. LPARAM lParam)
  154. {
  155. // @Oct/05/2000 ->
  156. #if !defined(GWMODEL) || defined(JOBLOGSUPPORT_DLG)
  157. if (OEMDocumentPropertySheets(pPSUIInfo, lParam))
  158. return S_OK;
  159. else
  160. return E_FAIL;
  161. #else // !(defined(GWMODEL) || defined(JOBLOGSUPPORT_DLG))
  162. return E_NOTIMPL;
  163. #endif // !(defined(GWMODEL) || defined(JOBLOGSUPPORT_DLG))
  164. // @Oct/05/2000 <-
  165. }
  166. //
  167. // DevicePropertySheets
  168. //
  169. STDMETHODIMP
  170. DevicePropertySheets(
  171. PPROPSHEETUI_INFO pPSUIInfo,
  172. LPARAM lParam)
  173. {
  174. return E_NOTIMPL;
  175. }
  176. //
  177. // DevQueryPrintEx
  178. //
  179. STDMETHODIMP
  180. DevQueryPrintEx(
  181. POEMUIOBJ poemuiobj,
  182. PDEVQUERYPRINT_INFO pDQPInfo,
  183. PDEVMODE pPublicDM,
  184. PVOID pOEMDM)
  185. {
  186. return E_NOTIMPL;
  187. }
  188. //
  189. // DeviceCapabilities
  190. //
  191. STDMETHODIMP
  192. DeviceCapabilities(
  193. POEMUIOBJ poemuiobj,
  194. HANDLE hPrinter,
  195. PWSTR pDeviceName,
  196. WORD wCapability,
  197. PVOID pOutput,
  198. PDEVMODE pPublicDM,
  199. PVOID pOEMDM,
  200. DWORD dwOld,
  201. DWORD *dwResult)
  202. {
  203. return E_NOTIMPL;
  204. }
  205. //
  206. // UpgradePrinter
  207. //
  208. STDMETHODIMP
  209. UpgradePrinter(
  210. DWORD dwLevel,
  211. PBYTE pDriverUpgradeInfo)
  212. {
  213. return E_NOTIMPL;
  214. }
  215. //
  216. // PrinterEvent
  217. //
  218. STDMETHODIMP
  219. PrinterEvent(
  220. PWSTR pPrinterName,
  221. INT iDriverEvent,
  222. DWORD dwFlags,
  223. LPARAM lParam)
  224. {
  225. return E_NOTIMPL;
  226. }
  227. //
  228. // DriverEvent
  229. //
  230. STDMETHODIMP
  231. DriverEvent(
  232. DWORD dwDriverEvent,
  233. DWORD dwLevel,
  234. LPBYTE pDriverInfo,
  235. LPARAM lParam)
  236. {
  237. return E_NOTIMPL;
  238. }
  239. //
  240. // QueryColorProfile
  241. //
  242. STDMETHODIMP
  243. QueryColorProfile(
  244. HANDLE hPrinter,
  245. POEMUIOBJ poemuiobj,
  246. PDEVMODE pPublicDM,
  247. PVOID pOEMDM,
  248. ULONG ulReserved,
  249. VOID *pvProfileData,
  250. ULONG *pcbProfileData,
  251. FLONG *pflProfileData)
  252. {
  253. return E_NOTIMPL;
  254. }
  255. //
  256. // FontInstallerDlgProc
  257. //
  258. STDMETHODIMP
  259. FontInstallerDlgProc(
  260. HWND hWnd,
  261. UINT usMsg,
  262. // @Apr/22/99 ->
  263. // WORD wParam,
  264. WPARAM wParam,
  265. // @Apr/22/99 <-
  266. LPARAM lParam)
  267. {
  268. return E_NOTIMPL;
  269. }
  270. //
  271. // UpdateExternalFonts
  272. //
  273. STDMETHODIMP
  274. UpdateExternalFonts(
  275. HANDLE hPrinter,
  276. HANDLE hHeap,
  277. PWSTR pwstrCartridges)
  278. {
  279. return E_NOTIMPL;
  280. }
  281. //
  282. // Constructors
  283. //
  284. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  285. ~IOemCB() { };
  286. protected:
  287. IPrintOemDriverUI* pOEMHelp;
  288. LONG m_cRef;
  289. };
  290. //
  291. // Class factory definition
  292. //
  293. class IOemCF : public IClassFactory
  294. {
  295. public:
  296. //
  297. // IUnknown methods
  298. //
  299. STDMETHODIMP
  300. QueryInterface(const IID& iid, void** ppv)
  301. {
  302. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  303. {
  304. *ppv = static_cast<IOemCF*>(this);
  305. }
  306. else
  307. {
  308. *ppv = NULL ;
  309. return E_NOINTERFACE ;
  310. }
  311. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  312. return S_OK ;
  313. }
  314. STDMETHODIMP_(ULONG)
  315. AddRef()
  316. {
  317. return InterlockedIncrement(&m_cRef);
  318. }
  319. STDMETHODIMP_(ULONG)
  320. Release()
  321. {
  322. if (InterlockedDecrement(&m_cRef) == 0)
  323. {
  324. delete this ;
  325. return 0 ;
  326. }
  327. return m_cRef ;
  328. }
  329. //
  330. // IClassFactory methods
  331. //
  332. STDMETHODIMP
  333. CreateInstance(
  334. IUnknown *pUnknownOuter,
  335. const IID &iid,
  336. void **ppv)
  337. {
  338. //VERBOSE((DLLTEXT("IOemCF::CreateInstance() called\n.")));
  339. // Cannot aggregate.
  340. if (NULL != pUnknownOuter) {
  341. return CLASS_E_NOAGGREGATION;
  342. }
  343. // Create component.
  344. IOemCB* pOemCB = new IOemCB;
  345. if (NULL == pOemCB) {
  346. return E_OUTOFMEMORY;
  347. }
  348. // Get the requested interface.
  349. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  350. // Release the IUnknown pointer.
  351. // (If QueryInterface failed, component will delete itself.)
  352. pOemCB->Release();
  353. return hr ;
  354. }
  355. // LockServer
  356. STDMETHODIMP
  357. LockServer(BOOL bLock)
  358. {
  359. if (bLock)
  360. InterlockedIncrement(&g_cServerLocks);
  361. else
  362. InterlockedDecrement(&g_cServerLocks);
  363. return S_OK ;
  364. }
  365. //
  366. // Constructor
  367. //
  368. IOemCF(): m_cRef(1) { };
  369. ~IOemCF() { };
  370. protected:
  371. LONG m_cRef;
  372. };
  373. //
  374. // Export functions
  375. //
  376. //
  377. // Get class factory
  378. //
  379. STDAPI
  380. DllGetClassObject(
  381. const CLSID &clsid,
  382. const IID &iid,
  383. void **ppv)
  384. {
  385. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  386. // Can we create this component?
  387. if (clsid != CLSID_OEMUI)
  388. {
  389. return CLASS_E_CLASSNOTAVAILABLE ;
  390. }
  391. // Create class factory.
  392. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  393. // in constructor
  394. if (pFontCF == NULL)
  395. {
  396. return E_OUTOFMEMORY ;
  397. }
  398. // Get requested interface.
  399. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  400. pFontCF->Release();
  401. return hr ;
  402. }
  403. //
  404. //
  405. // Can DLL unload now?
  406. //
  407. STDAPI
  408. DllCanUnloadNow()
  409. {
  410. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  411. return S_OK;
  412. // @Mar/29/2002 (MS)
  413. // else
  414. // return E_FAIL;
  415. else
  416. return S_FALSE;
  417. // @Mar/29/2002
  418. }