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.

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