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.

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