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.

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