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.

820 lines
18 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 rendering 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 plugin from RPDL code.
  11. 11/13/2001 -Masatoshi Kubokura-
  12. Last Modified for XP inbox.
  13. 02/26/2002 -Masatoshi Kubokura-
  14. Include strsafe.h.
  15. 03/29/2002 -Masatoshi Kubokura-
  16. Check NULL pointer at QueryInterface(), EnablePDEV(), and CommandCallback().
  17. --*/
  18. #define INITGUID // for GUID one-time initialization
  19. #include "pdev.h"
  20. #include "names.h"
  21. #ifndef WINNT_40
  22. #include "strsafe.h" // @Feb/26/2002
  23. #endif // !WINNT_40
  24. // Globals
  25. static HMODULE g_hModule = NULL ; // DLL module handle
  26. static long g_cComponents = 0 ; // Count of active components
  27. static long g_cServerLocks = 0 ; // Count of locks
  28. //
  29. // IOemCB Definition
  30. //
  31. class IOemCB : public IPrintOemUni
  32. {
  33. public:
  34. //
  35. // IUnknown methods
  36. //
  37. STDMETHODIMP
  38. QueryInterface(
  39. const IID& iid, void** ppv)
  40. {
  41. VERBOSE((DLLTEXT("IOemCB: QueryInterface entry\n")));
  42. // @Mar/29/2002 ->
  43. if (NULL == ppv)
  44. return E_FAIL;
  45. // @Mar/29/2002 <-
  46. if (iid == IID_IUnknown)
  47. {
  48. *ppv = static_cast<IUnknown*>(this);
  49. VERBOSE((DLLTEXT("IOemCB:Return pointer to IUnknown.\n")));
  50. }
  51. else if (iid == IID_IPrintOemUni)
  52. {
  53. *ppv = static_cast<IPrintOemUni*>(this);
  54. VERBOSE((DLLTEXT("IOemCB:Return pointer to IPrintOemUni.\n")));
  55. }
  56. else
  57. {
  58. *ppv = NULL ;
  59. VERBOSE((DLLTEXT("IOemCB:Return NULL.\n")));
  60. return E_NOINTERFACE ;
  61. }
  62. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  63. return S_OK ;
  64. }
  65. STDMETHODIMP_(ULONG)
  66. AddRef()
  67. {
  68. VERBOSE((DLLTEXT("IOemCB::AddRef() entry.\n")));
  69. return InterlockedIncrement(&m_cRef);
  70. }
  71. STDMETHODIMP_(ULONG)
  72. Release()
  73. {
  74. VERBOSE((DLLTEXT("IOemCB::Release() entry.\n")));
  75. if (InterlockedDecrement(&m_cRef) == 0)
  76. {
  77. delete this ;
  78. return 0 ;
  79. }
  80. return m_cRef ;
  81. }
  82. //
  83. // IPrintOemCommon methods
  84. //
  85. // Function Name: GetInfo
  86. // Plug-in: Any
  87. // Driver: Any
  88. // Type: Mandatory
  89. //
  90. STDMETHODIMP
  91. GetInfo(
  92. DWORD dwMode,
  93. PVOID pBuffer,
  94. DWORD cbSize,
  95. PDWORD pcbNeeded)
  96. {
  97. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  98. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  99. return S_OK;
  100. else
  101. return E_FAIL;
  102. }
  103. //
  104. // Function Name: DevMode
  105. // Plug-in: Rendering module
  106. // Driver: Any
  107. // Type: Optional
  108. //
  109. STDMETHODIMP
  110. DevMode(
  111. DWORD dwMode,
  112. POEMDMPARAM pOemDMParam)
  113. {
  114. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  115. if (OEMDevMode(dwMode, pOemDMParam)) {
  116. return S_OK;
  117. }
  118. else {
  119. return E_FAIL;
  120. }
  121. }
  122. //
  123. // IPrintOemEngine methods
  124. //
  125. //
  126. // Function Name: EnableDriver
  127. // Plug-in: Rendering module
  128. // Driver: Any
  129. // Type: Optional
  130. //
  131. STDMETHODIMP
  132. EnableDriver(
  133. DWORD dwDriverVersion,
  134. DWORD cbSize,
  135. PDRVENABLEDATA pded)
  136. {
  137. VERBOSE((DLLTEXT("IOemCB::EnableDriver() entry.\n")));
  138. // return E_NOTIMPL;
  139. OEMEnableDriver(dwDriverVersion, cbSize, pded);
  140. // Need to return S_OK so that DisableDriver() will be called, which Releases
  141. // the reference to the Printer Driver's interface.
  142. return S_OK;
  143. }
  144. //
  145. // Function Name: DisableDriver
  146. // Plug-in: Rendering module
  147. // Driver: Any
  148. // Type: Optional
  149. //
  150. STDMETHODIMP
  151. DisableDriver(VOID)
  152. {
  153. VERBOSE((DLLTEXT("IOemCB::DisaleDriver() entry.\n")));
  154. // return E_NOTIMPL;
  155. OEMDisableDriver();
  156. // Release reference to Printer Driver's interface.
  157. if (this->pOEMHelp)
  158. {
  159. this->pOEMHelp->Release();
  160. this->pOEMHelp = NULL;
  161. }
  162. return S_OK;
  163. }
  164. //
  165. // Function Name: EnablePDEV
  166. // Plug-in: Rendering module
  167. // Driver: Any
  168. // Type: Optional
  169. //
  170. STDMETHODIMP
  171. EnablePDEV(
  172. PDEVOBJ pdevobj,
  173. PWSTR pPrinterName,
  174. ULONG cPatterns,
  175. HSURF *phsurfPatterns,
  176. ULONG cjGdiInfo,
  177. GDIINFO *pGdiInfo,
  178. ULONG cjDevInfo,
  179. DEVINFO *pDevInfo,
  180. DRVENABLEDATA *pded,
  181. OUT PDEVOEM *pDevOem)
  182. {
  183. VERBOSE((DLLTEXT("IOemCB::EnablePDEV() entry.\n")));
  184. // return E_NOTIMPL;
  185. PDEVOEM pTemp;
  186. // @Mar/29/2002 ->
  187. if (NULL == pDevOem)
  188. return E_FAIL;
  189. // @Mar/29/2002 <-
  190. pTemp = OEMEnablePDEV(pdevobj, pPrinterName, cPatterns, phsurfPatterns,
  191. cjGdiInfo, pGdiInfo, cjDevInfo, pDevInfo, pded);
  192. if (NULL == pTemp)
  193. return E_FAIL;
  194. //
  195. // Save necessary helpder function addresses.
  196. //
  197. // ((MINIDEV *)pTemp)->pIntf = this->pOEMHelp;
  198. *pDevOem = pTemp;
  199. return S_OK;
  200. }
  201. //
  202. // Function Name: DisablePDEV
  203. // Plug-in: Rendering module
  204. // Driver: Any
  205. // Type: Optional
  206. //
  207. STDMETHODIMP
  208. DisablePDEV(
  209. PDEVOBJ pdevobj)
  210. {
  211. LONG lI;
  212. VERBOSE((DLLTEXT("IOemCB::DisablePDEV() entry.\n")));
  213. // return E_NOTIMPL;
  214. OEMDisablePDEV(pdevobj);
  215. return S_OK;
  216. }
  217. //
  218. // Function Name: ResetPDEV
  219. // Plug-in: Rendering module
  220. // Driver: Any
  221. // Type: Optional
  222. //
  223. STDMETHODIMP
  224. ResetPDEV(
  225. PDEVOBJ pdevobjOld,
  226. PDEVOBJ pdevobjNew)
  227. {
  228. VERBOSE((DLLTEXT("IOemCB::ResetPDEV() entry.\n")));
  229. // return E_NOTIMPL;
  230. if (OEMResetPDEV(pdevobjOld, pdevobjNew))
  231. return S_OK;
  232. // @Mar/26/2002 (MS) ->
  233. // else
  234. // return S_FALSE;
  235. else
  236. return E_FAIL;
  237. // @Mar/26/2002 <-
  238. }
  239. //
  240. // IPrintOemUni methods
  241. //
  242. //
  243. // Function Name: PublishDriverInterface
  244. // Plug-in: Rendering module
  245. // Driver: Any
  246. // Type: Mandatory
  247. //
  248. STDMETHODIMP
  249. PublishDriverInterface(
  250. IUnknown *pIUnknown)
  251. {
  252. VERBOSE((DLLTEXT("IOemCB::PublishDriverInterface() entry.\n")));
  253. // Need to store pointer to Driver Helper functions, if we already haven't.
  254. if (this->pOEMHelp == NULL)
  255. // pIUnknown->AddRef();
  256. {
  257. HRESULT hResult;
  258. // Get Interface to Helper Functions.
  259. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUni, (void**)&(this->pOEMHelp));
  260. if(!SUCCEEDED(hResult))
  261. {
  262. // Make sure that interface pointer reflects interface query failure.
  263. this->pOEMHelp = NULL;
  264. return E_FAIL;
  265. }
  266. }
  267. // this->pOEMHelp = reinterpret_cast<IPrintOemDriverUni*>(pIUnknown);
  268. return S_OK;
  269. }
  270. //
  271. // Function Name: GetImplementationMethod
  272. // Plug-in: Rendering module
  273. // Driver: Any
  274. // Type: Mandatory
  275. //
  276. //
  277. // Needed to be static so that it can be passed
  278. // to the bsearch() as a pointer to a functin.
  279. //
  280. static
  281. int __cdecl
  282. iCompNames(
  283. const void *p1,
  284. const void *p2) {
  285. return strcmp(
  286. *((char **)p1),
  287. *((char **)p2));
  288. }
  289. STDMETHODIMP
  290. GetImplementedMethod(
  291. PSTR pMethodName)
  292. {
  293. LONG lRet = E_NOTIMPL;
  294. PSTR pTemp;
  295. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  296. if (NULL != pMethodName) {
  297. pTemp = (PSTR)bsearch(
  298. &pMethodName,
  299. gMethodsSupported,
  300. (sizeof (gMethodsSupported) / sizeof (PSTR)),
  301. sizeof (PSTR),
  302. iCompNames);
  303. if (NULL != pTemp)
  304. lRet = S_OK;
  305. }
  306. VERBOSE((DLLTEXT("pMethodName = %s, lRet = %d\n"), pMethodName, lRet));
  307. return lRet;
  308. }
  309. //
  310. // Function Name: CommandCallback
  311. // Plug-in: Rendering module
  312. // Driver: Unidrv
  313. // Type: Optional
  314. //
  315. STDMETHODIMP
  316. CommandCallback(
  317. PDEVOBJ pdevobj,
  318. DWORD dwCallbackID,
  319. DWORD dwCount,
  320. PDWORD pdwParams,
  321. OUT INT *piResult)
  322. {
  323. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\n")));
  324. // @Mar/29/2002 ->
  325. if (NULL == piResult)
  326. return E_FAIL;
  327. // @Mar/29/2002 <-
  328. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  329. return S_OK;
  330. }
  331. //
  332. // Function Name: ImageProcessing
  333. // Plug-in: Rendering module
  334. // Driver: Unidrv
  335. // Type: Optional
  336. //
  337. STDMETHODIMP
  338. ImageProcessing(
  339. PDEVOBJ pdevobj,
  340. PBYTE pSrcBitmap,
  341. PBITMAPINFOHEADER pBitmapInfoHeader,
  342. PBYTE pColorTable,
  343. DWORD dwCallbackID,
  344. PIPPARAMS pIPParams,
  345. OUT PBYTE *ppbResult)
  346. {
  347. VERBOSE((DLLTEXT("IOemCB::ImageProcessing() entry.\n")));
  348. return E_NOTIMPL;
  349. }
  350. //
  351. // Function Name: FilterGraphics
  352. // Plug-in: Rendering module
  353. // Driver: Unidrv
  354. // Type: Optional
  355. //
  356. STDMETHODIMP
  357. FilterGraphics(
  358. PDEVOBJ pdevobj,
  359. PBYTE pBuf,
  360. DWORD dwLen)
  361. {
  362. VERBOSE((DLLTEXT("IOemCB::FilterGraphis() entry.\n")));
  363. return E_NOTIMPL;
  364. }
  365. //
  366. // Function Name: Compression
  367. // Plug-in: Rendering module
  368. // Driver: Unidrv
  369. // Type: Optional
  370. //
  371. STDMETHODIMP
  372. Compression(
  373. PDEVOBJ pdevobj,
  374. PBYTE pInBuf,
  375. PBYTE pOutBuf,
  376. DWORD dwInLen,
  377. DWORD dwOutLen,
  378. OUT INT *piResult)
  379. {
  380. VERBOSE((DLLTEXT("IOemCB::Compression() entry.\n")));
  381. return E_NOTIMPL;
  382. }
  383. //
  384. // Function Name: HalftonePattern
  385. // Plug-in: Rendering module
  386. // Driver: Unidrv
  387. // Type: Optional
  388. //
  389. STDMETHODIMP
  390. HalftonePattern(
  391. PDEVOBJ pdevobj,
  392. PBYTE pHTPattern,
  393. DWORD dwHTPatternX,
  394. DWORD dwHTPatternY,
  395. DWORD dwHTNumPatterns,
  396. DWORD dwCallbackID,
  397. PBYTE pResource,
  398. DWORD dwResourceSize)
  399. {
  400. VERBOSE((DLLTEXT("IOemCB::HalftonePattern() entry.\n")));
  401. #ifdef WINNT_40 // @Nov/13/2001
  402. return E_NOTIMPL;
  403. #else // !WINNT_40
  404. // @Sep/28/2001 ->
  405. if (OEMHalftonePattern(pdevobj, pHTPattern, dwHTPatternX, dwHTPatternY,
  406. dwHTNumPatterns, dwCallbackID, pResource, dwResourceSize))
  407. return S_OK;
  408. else
  409. return E_FAIL;
  410. // @Sep/28/2001 <-
  411. #endif // !WINNT_40
  412. }
  413. //
  414. // Function Name: MemoryUsge
  415. // Plug-in: Rendering module
  416. // Driver: Unidrv
  417. // Type: Optional
  418. //
  419. STDMETHODIMP
  420. MemoryUsage(
  421. PDEVOBJ pdevobj,
  422. POEMMEMORYUSAGE pMemoryUsage)
  423. {
  424. VERBOSE((DLLTEXT("IOemCB::MemoryUsage() entry.\n")));
  425. return E_NOTIMPL;
  426. }
  427. //
  428. // Function Name: DownloadFontHeader
  429. // Plug-in: Rendering module
  430. // Driver: Unidrv
  431. // Type: Optional
  432. //
  433. STDMETHODIMP
  434. DownloadFontHeader(
  435. PDEVOBJ pdevobj,
  436. PUNIFONTOBJ pUFObj,
  437. OUT DWORD *pdwResult)
  438. {
  439. VERBOSE((DLLTEXT("IOemCB::DownloadFontHeader() entry.\n")));
  440. return E_NOTIMPL;
  441. }
  442. //
  443. // Function Name: DownloadCharGlyph
  444. // Plug-in: Rendering module
  445. // Driver: Unidrv
  446. // Type: Optional
  447. //
  448. STDMETHODIMP
  449. DownloadCharGlyph(
  450. PDEVOBJ pdevobj,
  451. PUNIFONTOBJ pUFObj,
  452. HGLYPH hGlyph,
  453. PDWORD pdwWidth,
  454. OUT DWORD *pdwResult)
  455. {
  456. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  457. return E_NOTIMPL;
  458. }
  459. //
  460. // Function Name: TTDonwloadMethod
  461. // Plug-in: Rendering module
  462. // Driver: Unidrv
  463. // Type: Optional
  464. //
  465. STDMETHODIMP
  466. TTDownloadMethod(
  467. PDEVOBJ pdevobj,
  468. PUNIFONTOBJ pUFObj,
  469. OUT DWORD *pdwResult)
  470. {
  471. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  472. return E_NOTIMPL;
  473. }
  474. //
  475. // Function Name: OutputCharStr
  476. // Plug-in: Rendering module
  477. // Driver: Unidrv
  478. // Type: Optional
  479. //
  480. STDMETHODIMP
  481. OutputCharStr(
  482. PDEVOBJ pdevobj,
  483. PUNIFONTOBJ pUFObj,
  484. DWORD dwType,
  485. DWORD dwCount,
  486. PVOID pGlyph)
  487. {
  488. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  489. return E_NOTIMPL;
  490. }
  491. //
  492. // Function Name: SendFontCmd
  493. // Plug-in: Rendering module
  494. // Driver: Unidrv
  495. // Type: Optional
  496. //
  497. STDMETHODIMP
  498. SendFontCmd(
  499. PDEVOBJ pdevobj,
  500. PUNIFONTOBJ pUFObj,
  501. PFINVOCATION pFInv)
  502. {
  503. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  504. return E_NOTIMPL;
  505. }
  506. //
  507. // Function Name: DriverDMS
  508. // Plug-in: Rendering module
  509. // Driver: Unidrv
  510. // Type: Optional
  511. //
  512. STDMETHODIMP
  513. DriverDMS(
  514. PVOID pDevObj,
  515. PVOID pBuffer,
  516. DWORD cbSize,
  517. PDWORD pcbNeeded)
  518. {
  519. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  520. return E_NOTIMPL;
  521. }
  522. //
  523. // Function Name: TextOutputAsBitmap
  524. // Plug-in: Rendering module
  525. // Driver: Unidrv
  526. // Type: Optional
  527. //
  528. STDMETHODIMP
  529. TextOutAsBitmap(
  530. SURFOBJ *pso,
  531. STROBJ *pstro,
  532. FONTOBJ *pfo,
  533. CLIPOBJ *pco,
  534. RECTL *prclExtra,
  535. RECTL *prclOpaque,
  536. BRUSHOBJ *pboFore,
  537. BRUSHOBJ *pboOpaque,
  538. POINTL *pptlOrg,
  539. MIX mix)
  540. {
  541. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  542. return E_NOTIMPL;
  543. }
  544. //
  545. // Function Name: TTYGetInfo
  546. // Plug-in: Rendering module
  547. // Driver: Unidrv
  548. // Type: Optional
  549. //
  550. STDMETHODIMP
  551. TTYGetInfo(
  552. PDEVOBJ pdevobj,
  553. DWORD dwInfoIndex,
  554. PVOID pOutputBuf,
  555. DWORD dwSize,
  556. DWORD *pcbcNeeded)
  557. {
  558. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  559. return E_NOTIMPL;
  560. }
  561. //
  562. // Constructors
  563. //
  564. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  565. ~IOemCB() { };
  566. protected:
  567. IPrintOemDriverUni* pOEMHelp;
  568. LONG m_cRef;
  569. };
  570. //
  571. // Class factory definition
  572. //
  573. class IOemCF : public IClassFactory
  574. {
  575. public:
  576. //
  577. // IUnknown methods
  578. //
  579. STDMETHODIMP
  580. QueryInterface(const IID& iid, void** ppv)
  581. {
  582. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  583. {
  584. *ppv = static_cast<IOemCF*>(this);
  585. }
  586. else
  587. {
  588. *ppv = NULL ;
  589. return E_NOINTERFACE ;
  590. }
  591. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  592. return S_OK ;
  593. }
  594. STDMETHODIMP_(ULONG)
  595. AddRef()
  596. {
  597. return InterlockedIncrement(&m_cRef);
  598. }
  599. STDMETHODIMP_(ULONG)
  600. Release()
  601. {
  602. if (InterlockedDecrement(&m_cRef) == 0)
  603. {
  604. delete this ;
  605. return 0 ;
  606. }
  607. return m_cRef ;
  608. }
  609. //
  610. // IClassFactory methods
  611. //
  612. STDMETHODIMP
  613. CreateInstance(
  614. IUnknown *pUnknownOuter,
  615. const IID &iid,
  616. void **ppv)
  617. {
  618. //VERBOSE((DLLTEXT("IOemCF::CreateInstance() called\n.")));
  619. // Cannot aggregate.
  620. if (NULL != pUnknownOuter) {
  621. return CLASS_E_NOAGGREGATION;
  622. }
  623. // Create component.
  624. IOemCB* pOemCB = new IOemCB;
  625. if (NULL == pOemCB) {
  626. return E_OUTOFMEMORY;
  627. }
  628. // Get the requested interface.
  629. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  630. // Release the IUnknown pointer.
  631. // (If QueryInterface failed, component will delete itself.)
  632. pOemCB->Release();
  633. return hr ;
  634. }
  635. // LockServer
  636. STDMETHODIMP
  637. LockServer(BOOL bLock)
  638. {
  639. if (bLock)
  640. {
  641. InterlockedIncrement(&g_cServerLocks);
  642. }
  643. else
  644. {
  645. InterlockedDecrement(&g_cServerLocks);
  646. }
  647. return S_OK ;
  648. }
  649. //
  650. // Constructor
  651. //
  652. IOemCF(): m_cRef(1) { };
  653. ~IOemCF() { };
  654. protected:
  655. LONG m_cRef;
  656. };
  657. //
  658. // Export functions
  659. //
  660. //
  661. // Get class factory
  662. //
  663. STDAPI
  664. DllGetClassObject(
  665. const CLSID &clsid,
  666. const IID &iid,
  667. void **ppv)
  668. {
  669. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  670. // Can we create this component?
  671. if (clsid != CLSID_OEMRENDER)
  672. {
  673. return CLASS_E_CLASSNOTAVAILABLE ;
  674. }
  675. // Create class factory.
  676. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  677. // in constructor
  678. if (pFontCF == NULL)
  679. {
  680. return E_OUTOFMEMORY ;
  681. }
  682. // Get requested interface.
  683. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  684. pFontCF->Release();
  685. return hr ;
  686. }
  687. //
  688. //
  689. // Can DLL unload now?
  690. //
  691. STDAPI
  692. DllCanUnloadNow()
  693. {
  694. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  695. {
  696. return S_OK;
  697. }
  698. else
  699. {
  700. // @Mar/26/2002 (MS) ->
  701. // return E_FAIL;
  702. return S_FALSE;
  703. // @Mar/26/2002 <-
  704. }
  705. }