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.

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