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.

837 lines
18 KiB

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