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.

818 lines
17 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-588586-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. return E_NOTIMPL;
  321. }
  322. //
  323. // Function Name: FilterGraphics
  324. // Plug-in: Rendering module
  325. // Driver: Unidrv
  326. // Type: Optional
  327. //
  328. STDMETHODIMP
  329. FilterGraphics(
  330. PDEVOBJ pdevobj,
  331. PBYTE pBuf,
  332. DWORD dwLen)
  333. {
  334. VERBOSE(("IOemCB::FilterGraphis() entry.\n"));
  335. return E_NOTIMPL;
  336. }
  337. //
  338. // Function Name: Compression
  339. // Plug-in: Rendering module
  340. // Driver: Unidrv
  341. // Type: Optional
  342. //
  343. STDMETHODIMP
  344. Compression(
  345. PDEVOBJ pdevobj,
  346. PBYTE pInBuf,
  347. PBYTE pOutBuf,
  348. DWORD dwInLen,
  349. DWORD dwOutLen,
  350. OUT INT *piResult)
  351. {
  352. VERBOSE(("IOemCB::Compression() entry.\n"));
  353. return E_NOTIMPL;
  354. }
  355. //
  356. // Function Name: HalftonePattern
  357. // Plug-in: Rendering module
  358. // Driver: Unidrv
  359. // Type: Optional
  360. //
  361. STDMETHODIMP
  362. HalftonePattern(
  363. PDEVOBJ pdevobj,
  364. PBYTE pHTPattern,
  365. DWORD dwHTPatternX,
  366. DWORD dwHTPatternY,
  367. DWORD dwHTNumPatterns,
  368. DWORD dwCallbackID,
  369. PBYTE pResource,
  370. DWORD dwResourceSize)
  371. {
  372. VERBOSE(("IOemCB::HalftonePattern() entry.\n"));
  373. return E_NOTIMPL;
  374. }
  375. //
  376. // Function Name: MemoryUsge
  377. // Plug-in: Rendering module
  378. // Driver: Unidrv
  379. // Type: Optional
  380. //
  381. STDMETHODIMP
  382. MemoryUsage(
  383. PDEVOBJ pdevobj,
  384. POEMMEMORYUSAGE pMemoryUsage)
  385. {
  386. VERBOSE(("IOemCB::MemoryUsage() entry.\n"));
  387. return E_NOTIMPL;
  388. }
  389. //
  390. // Function Name: DownloadFontHeader
  391. // Plug-in: Rendering module
  392. // Driver: Unidrv
  393. // Type: Optional
  394. //
  395. STDMETHODIMP
  396. DownloadFontHeader(
  397. PDEVOBJ pdevobj,
  398. PUNIFONTOBJ pUFObj,
  399. OUT DWORD *pdwResult)
  400. {
  401. VERBOSE(("IOemCB::DownloadFontHeader() entry.\n"));
  402. #if DOWNLOADFONT
  403. if (0 < (*pdwResult = OEMDownloadFontHeader(pdevobj, pUFObj))) {
  404. return S_OK;
  405. }
  406. else {
  407. return E_FAIL;
  408. }
  409. #else // DOWNLOADFONT
  410. return E_NOTIMPL;
  411. #endif // DOWNLOADFONT
  412. }
  413. //
  414. // Function Name: DownloadCharGlyph
  415. // Plug-in: Rendering module
  416. // Driver: Unidrv
  417. // Type: Optional
  418. //
  419. STDMETHODIMP
  420. DownloadCharGlyph(
  421. PDEVOBJ pdevobj,
  422. PUNIFONTOBJ pUFObj,
  423. HGLYPH hGlyph,
  424. PDWORD pdwWidth,
  425. OUT DWORD *pdwResult)
  426. {
  427. VERBOSE(("IOemCB::DownloadCharGlyph() entry.\n"));
  428. #if DOWNLOADFONT
  429. if (0 < (*pdwResult = OEMDownloadCharGlyph(pdevobj, pUFObj,
  430. hGlyph, pdwWidth))) {
  431. return S_OK;
  432. }
  433. else {
  434. return E_FAIL;
  435. }
  436. #else // DOWNLOADFONT
  437. return E_NOTIMPL;
  438. #endif // DOWNLOADFONT
  439. }
  440. //
  441. // Function Name: TTDonwloadMethod
  442. // Plug-in: Rendering module
  443. // Driver: Unidrv
  444. // Type: Optional
  445. //
  446. STDMETHODIMP
  447. TTDownloadMethod(
  448. PDEVOBJ pdevobj,
  449. PUNIFONTOBJ pUFObj,
  450. OUT DWORD *pdwResult)
  451. {
  452. VERBOSE(("IOemCB::TTDownloadMethod() entry.\n"));
  453. #if DOWNLOADFONT
  454. *pdwResult = OEMTTDownloadMethod(pdevobj, pUFObj);
  455. return S_OK;
  456. #else // DOWNLOADFONT
  457. return E_NOTIMPL;
  458. #endif // DOWNLOADFONT
  459. }
  460. //
  461. // Function Name: OutputCharStr
  462. // Plug-in: Rendering module
  463. // Driver: Unidrv
  464. // Type: Optional
  465. //
  466. STDMETHODIMP
  467. OutputCharStr(
  468. PDEVOBJ pdevobj,
  469. PUNIFONTOBJ pUFObj,
  470. DWORD dwType,
  471. DWORD dwCount,
  472. PVOID pGlyph)
  473. {
  474. VERBOSE(("IOemCB::OutputCharStr() entry.\n"));
  475. OEMOutputCharStr(pdevobj, pUFObj, dwType, dwCount, pGlyph);
  476. return S_OK;
  477. }
  478. //
  479. // Function Name: SendFontCmd
  480. // Plug-in: Rendering module
  481. // Driver: Unidrv
  482. // Type: Optional
  483. //
  484. STDMETHODIMP
  485. SendFontCmd(
  486. PDEVOBJ pdevobj,
  487. PUNIFONTOBJ pUFObj,
  488. PFINVOCATION pFInv)
  489. {
  490. VERBOSE(("IOemCB::SendFontCmd() entry.\n"));
  491. OEMSendFontCmd(pdevobj, pUFObj, pFInv);
  492. return S_OK;
  493. }
  494. //
  495. // Function Name: DriverDMS
  496. // Plug-in: Rendering module
  497. // Driver: Unidrv
  498. // Type: Optional
  499. //
  500. STDMETHODIMP
  501. DriverDMS(
  502. PVOID pDevObj,
  503. PVOID pBuffer,
  504. DWORD cbSize,
  505. PDWORD pcbNeeded)
  506. {
  507. VERBOSE(("IOemCB::DriverDMS() entry.\n"));
  508. return E_NOTIMPL;
  509. }
  510. //
  511. // Function Name: TextOutputAsBitmap
  512. // Plug-in: Rendering module
  513. // Driver: Unidrv
  514. // Type: Optional
  515. //
  516. STDMETHODIMP
  517. TextOutAsBitmap(
  518. SURFOBJ *pso,
  519. STROBJ *pstro,
  520. FONTOBJ *pfo,
  521. CLIPOBJ *pco,
  522. RECTL *prclExtra,
  523. RECTL *prclOpaque,
  524. BRUSHOBJ *pboFore,
  525. BRUSHOBJ *pboOpaque,
  526. POINTL *pptlOrg,
  527. MIX mix)
  528. {
  529. VERBOSE(("IOemCB::TextOutAsBitmap() entry.\n"));
  530. return E_NOTIMPL;
  531. }
  532. //
  533. // Function Name: TTYGetInfo
  534. // Plug-in: Rendering module
  535. // Driver: Unidrv
  536. // Type: Optional
  537. //
  538. STDMETHODIMP
  539. TTYGetInfo(
  540. PDEVOBJ pdevobj,
  541. DWORD dwInfoIndex,
  542. PVOID pOutputBuf,
  543. DWORD dwSize,
  544. DWORD *pcbcNeeded)
  545. {
  546. VERBOSE(("IOemCB::TTYGetInfo() entry.\n"));
  547. return E_NOTIMPL;
  548. }
  549. //
  550. // Constructors
  551. //
  552. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  553. ~IOemCB() { };
  554. protected:
  555. IPrintOemDriverUni* pOEMHelp;
  556. LONG m_cRef;
  557. };
  558. //
  559. // Class factory definition
  560. //
  561. class IOemCF : public IClassFactory
  562. {
  563. public:
  564. //
  565. // IUnknown methods
  566. //
  567. STDMETHODIMP
  568. QueryInterface(const IID& iid, void** ppv)
  569. {
  570. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  571. {
  572. *ppv = static_cast<IOemCF*>(this);
  573. }
  574. else
  575. {
  576. *ppv = NULL ;
  577. return E_NOINTERFACE ;
  578. }
  579. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  580. return S_OK ;
  581. }
  582. STDMETHODIMP_(ULONG)
  583. AddRef()
  584. {
  585. return InterlockedIncrement(&m_cRef);
  586. }
  587. STDMETHODIMP_(ULONG)
  588. Release()
  589. {
  590. if (InterlockedDecrement(&m_cRef) == 0)
  591. {
  592. delete this ;
  593. return 0 ;
  594. }
  595. return m_cRef ;
  596. }
  597. //
  598. // IClassFactory methods
  599. //
  600. STDMETHODIMP
  601. CreateInstance(
  602. IUnknown *pUnknownOuter,
  603. const IID &iid,
  604. void **ppv)
  605. {
  606. //VERBOSE(("IOemCF::CreateInstance() called\n."));
  607. // Cannot aggregate.
  608. if (NULL != pUnknownOuter) {
  609. return CLASS_E_NOAGGREGATION;
  610. }
  611. // Create component.
  612. IOemCB* pOemCB = new IOemCB;
  613. if (NULL == pOemCB) {
  614. return E_OUTOFMEMORY;
  615. }
  616. // Get the requested interface.
  617. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  618. // Release the IUnknown pointer.
  619. // (If QueryInterface failed, component will delete itself.)
  620. pOemCB->Release();
  621. return hr ;
  622. }
  623. // LockServer
  624. STDMETHODIMP
  625. LockServer(BOOL bLock)
  626. {
  627. if (bLock)
  628. {
  629. InterlockedIncrement(&g_cServerLocks);
  630. }
  631. else
  632. {
  633. InterlockedDecrement(&g_cServerLocks);
  634. }
  635. return S_OK ;
  636. }
  637. //
  638. // Constructor
  639. //
  640. IOemCF(): m_cRef(1) { };
  641. ~IOemCF() { };
  642. protected:
  643. LONG m_cRef;
  644. };
  645. //
  646. // Export functions
  647. //
  648. //
  649. // Get class factory
  650. //
  651. STDAPI
  652. DllGetClassObject(
  653. const CLSID &clsid,
  654. const IID &iid,
  655. void **ppv)
  656. {
  657. //VERBOSE(("DllGetClassObject:\tCreate class factory."));
  658. // Can we create this component?
  659. if (clsid != CLSID_OEMRENDER)
  660. {
  661. return CLASS_E_CLASSNOTAVAILABLE ;
  662. }
  663. // Create class factory.
  664. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  665. // in constructor
  666. if (pFontCF == NULL)
  667. {
  668. return E_OUTOFMEMORY ;
  669. }
  670. // Get requested interface.
  671. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  672. pFontCF->Release();
  673. return hr ;
  674. }
  675. //
  676. //
  677. // Can DLL unload now?
  678. //
  679. STDAPI
  680. DllCanUnloadNow()
  681. {
  682. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  683. {
  684. return S_OK;
  685. }
  686. else
  687. {
  688. return S_FALSE;
  689. }
  690. }