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.

791 lines
17 KiB

  1. /*++
  2. Copyright (c) 1996-1999 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-588580-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. if (ppv == NULL) return E_NOINTERFACE;
  36. VERBOSE((DLLTEXT("IOemCB: QueryInterface entry\n")));
  37. if (iid == IID_IUnknown)
  38. {
  39. *ppv = static_cast<IUnknown*>(this);
  40. VERBOSE((DLLTEXT("IOemCB:Return pointer to IUnknown.\n")));
  41. }
  42. else if (iid == IID_IPrintOemUni)
  43. {
  44. *ppv = static_cast<IPrintOemUni*>(this);
  45. VERBOSE((DLLTEXT("IOemCB:Return pointer to IPrintOemUni.\n")));
  46. }
  47. else
  48. {
  49. *ppv = NULL ;
  50. VERBOSE((DLLTEXT("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((DLLTEXT("IOemCB::AddRef() entry.\n")));
  60. return InterlockedIncrement(&m_cRef);
  61. }
  62. STDMETHODIMP_(ULONG)
  63. Release()
  64. {
  65. VERBOSE((DLLTEXT("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((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  89. // Parameters will be check in this function, OEMGetInfo().
  90. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  91. return S_OK;
  92. else
  93. return E_FAIL;
  94. }
  95. //
  96. // Function Name: DevMode
  97. // Plug-in: Rendering module
  98. // Driver: Any
  99. // Type: Optional
  100. //
  101. STDMETHODIMP
  102. DevMode(
  103. DWORD dwMode,
  104. POEMDMPARAM pOemDMParam)
  105. {
  106. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  107. // Parameters will be check in this function, OEMGetInfo().
  108. if (OEMDevMode(dwMode, pOemDMParam))
  109. return S_OK;
  110. else
  111. return E_FAIL;
  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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("IOemCB::EnablePDEV() entry.\n")));
  175. return E_NOTIMPL;
  176. }
  177. //
  178. // Function Name: DisablePDEV
  179. // Plug-in: Rendering module
  180. // Driver: Any
  181. // Type: Optional
  182. //
  183. STDMETHODIMP
  184. DisablePDEV(
  185. PDEVOBJ pdevobj)
  186. {
  187. LONG lI;
  188. VERBOSE((DLLTEXT("IOemCB::DisablePDEV() entry.\n")));
  189. return E_NOTIMPL;
  190. }
  191. //
  192. // Function Name: ResetPDEV
  193. // Plug-in: Rendering module
  194. // Driver: Any
  195. // Type: Optional
  196. //
  197. STDMETHODIMP
  198. ResetPDEV(
  199. PDEVOBJ pdevobjOld,
  200. PDEVOBJ pdevobjNew)
  201. {
  202. VERBOSE((DLLTEXT("IOemCB::ResetPDEV() entry.\n")));
  203. return E_NOTIMPL;
  204. }
  205. //
  206. // IPrintOemUni methods
  207. //
  208. //
  209. // Function Name: PublishDriverInterface
  210. // Plug-in: Rendering module
  211. // Driver: Any
  212. // Type: Mandatory
  213. //
  214. STDMETHODIMP
  215. PublishDriverInterface(
  216. IUnknown *pIUnknown)
  217. {
  218. VERBOSE((DLLTEXT("IOemCB::PublishDriverInterface() entry.\n")));
  219. // Sep.8.98 ->
  220. // Need to store pointer to Driver Helper functions, if we already haven't.
  221. if (this->pOEMHelp == NULL)
  222. {
  223. HRESULT hResult;
  224. if (pIUnknown == NULL) return E_FAIL;
  225. // Get Interface to Helper Functions.
  226. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUni, (void** )&(this->pOEMHelp));
  227. if(!SUCCEEDED(hResult))
  228. {
  229. // Make sure that interface pointer reflects interface query failure.
  230. this->pOEMHelp = NULL;
  231. return E_FAIL;
  232. }
  233. }
  234. // Sep.8.98 <-
  235. return S_OK;
  236. }
  237. //
  238. // Function Name: GetImplementationMethod
  239. // Plug-in: Rendering module
  240. // Driver: Any
  241. // Type: Mandatory
  242. //
  243. //
  244. // Needed to be static so that it can be passed
  245. // to the bsearch() as a pointer to a functin.
  246. //
  247. static
  248. int __cdecl
  249. iCompNames(
  250. const void *p1,
  251. const void *p2) {
  252. return strcmp(
  253. *((char **)p1),
  254. *((char **)p2));
  255. }
  256. STDMETHODIMP
  257. GetImplementedMethod(
  258. PSTR pMethodName)
  259. {
  260. LONG lRet = E_NOTIMPL;
  261. PSTR pTemp;
  262. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  263. if (NULL != pMethodName) {
  264. pTemp = (PSTR)bsearch(
  265. &pMethodName,
  266. gMethodsSupported,
  267. (sizeof (gMethodsSupported) / sizeof (PSTR)),
  268. sizeof (PSTR),
  269. iCompNames);
  270. if (NULL != pTemp)
  271. lRet = S_OK;
  272. }
  273. VERBOSE((DLLTEXT("pMethodName = %s, lRet = %d\n"), pMethodName, lRet));
  274. return lRet;
  275. }
  276. //
  277. // Function Name: CommandCallback
  278. // Plug-in: Rendering module
  279. // Driver: Unidrv
  280. // Type: Optional
  281. //
  282. STDMETHODIMP
  283. CommandCallback(
  284. PDEVOBJ pdevobj,
  285. DWORD dwCallbackID,
  286. DWORD dwCount,
  287. PDWORD pdwParams,
  288. OUT INT *piResult)
  289. {
  290. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\n")));
  291. // Added to check the NULL pointer.
  292. if (pdevobj == NULL) return E_FAIL;
  293. if (piResult == NULL) return E_FAIL;
  294. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  295. if (*piResult < 0)
  296. return E_FAIL;
  297. else
  298. return S_OK;
  299. }
  300. //
  301. // Function Name: ImageProcessing
  302. // Plug-in: Rendering module
  303. // Driver: Unidrv
  304. // Type: Optional
  305. //
  306. STDMETHODIMP
  307. ImageProcessing(
  308. PDEVOBJ pdevobj,
  309. PBYTE pSrcBitmap,
  310. PBITMAPINFOHEADER pBitmapInfoHeader,
  311. PBYTE pColorTable,
  312. DWORD dwCallbackID,
  313. PIPPARAMS pIPParams,
  314. OUT PBYTE *ppbResult)
  315. {
  316. VERBOSE((DLLTEXT("IOemCB::ImageProcessing() entry.\n")));
  317. return E_NOTIMPL;
  318. }
  319. //
  320. // Function Name: FilterGraphics
  321. // Plug-in: Rendering module
  322. // Driver: Unidrv
  323. // Type: Optional
  324. //
  325. STDMETHODIMP
  326. FilterGraphics(
  327. PDEVOBJ pdevobj,
  328. PBYTE pBuf,
  329. DWORD dwLen)
  330. {
  331. VERBOSE((DLLTEXT("IOemCB::FilterGraphis() entry.\n")));
  332. return E_NOTIMPL;
  333. }
  334. //
  335. // Function Name: Compression
  336. // Plug-in: Rendering module
  337. // Driver: Unidrv
  338. // Type: Optional
  339. //
  340. STDMETHODIMP
  341. Compression(
  342. PDEVOBJ pdevobj,
  343. PBYTE pInBuf,
  344. PBYTE pOutBuf,
  345. DWORD dwInLen,
  346. DWORD dwOutLen,
  347. OUT INT *piResult)
  348. {
  349. VERBOSE((DLLTEXT("IOemCB::Compression() entry.\n")));
  350. if (piResult == NULL) return E_FAIL;
  351. *piResult = OEMCompression(
  352. pdevobj, pInBuf, pOutBuf, dwInLen, dwOutLen);
  353. if (*piResult > 0)
  354. return S_OK;
  355. else
  356. return E_FAIL;
  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. return E_NOTIMPL;
  406. }
  407. //
  408. // Function Name: DownloadCharGlyph
  409. // Plug-in: Rendering module
  410. // Driver: Unidrv
  411. // Type: Optional
  412. //
  413. STDMETHODIMP
  414. DownloadCharGlyph(
  415. PDEVOBJ pdevobj,
  416. PUNIFONTOBJ pUFObj,
  417. HGLYPH hGlyph,
  418. PDWORD pdwWidth,
  419. OUT DWORD *pdwResult)
  420. {
  421. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  422. return E_NOTIMPL;
  423. }
  424. //
  425. // Function Name: TTDonwloadMethod
  426. // Plug-in: Rendering module
  427. // Driver: Unidrv
  428. // Type: Optional
  429. //
  430. STDMETHODIMP
  431. TTDownloadMethod(
  432. PDEVOBJ pdevobj,
  433. PUNIFONTOBJ pUFObj,
  434. OUT DWORD *pdwResult)
  435. {
  436. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  437. return E_NOTIMPL;
  438. }
  439. //
  440. // Function Name: OutputCharStr
  441. // Plug-in: Rendering module
  442. // Driver: Unidrv
  443. // Type: Optional
  444. //
  445. STDMETHODIMP
  446. OutputCharStr(
  447. PDEVOBJ pdevobj,
  448. PUNIFONTOBJ pUFObj,
  449. DWORD dwType,
  450. DWORD dwCount,
  451. PVOID pGlyph)
  452. {
  453. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  454. return E_NOTIMPL;
  455. }
  456. //
  457. // Function Name: SendFontCmd
  458. // Plug-in: Rendering module
  459. // Driver: Unidrv
  460. // Type: Optional
  461. //
  462. STDMETHODIMP
  463. SendFontCmd(
  464. PDEVOBJ pdevobj,
  465. PUNIFONTOBJ pUFObj,
  466. PFINVOCATION pFInv)
  467. {
  468. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  469. return E_NOTIMPL;
  470. }
  471. //
  472. // Function Name: DriverDMS
  473. // Plug-in: Rendering module
  474. // Driver: Unidrv
  475. // Type: Optional
  476. //
  477. STDMETHODIMP
  478. DriverDMS(
  479. PVOID pDevObj,
  480. PVOID pBuffer,
  481. DWORD cbSize,
  482. PDWORD pcbNeeded)
  483. {
  484. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  485. return E_NOTIMPL;
  486. }
  487. //
  488. // Function Name: TextOutputAsBitmap
  489. // Plug-in: Rendering module
  490. // Driver: Unidrv
  491. // Type: Optional
  492. //
  493. STDMETHODIMP
  494. TextOutAsBitmap(
  495. SURFOBJ *pso,
  496. STROBJ *pstro,
  497. FONTOBJ *pfo,
  498. CLIPOBJ *pco,
  499. RECTL *prclExtra,
  500. RECTL *prclOpaque,
  501. BRUSHOBJ *pboFore,
  502. BRUSHOBJ *pboOpaque,
  503. POINTL *pptlOrg,
  504. MIX mix)
  505. {
  506. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  507. return E_NOTIMPL;
  508. }
  509. //
  510. // Function Name: TTYGetInfo
  511. // Plug-in: Rendering module
  512. // Driver: Unidrv
  513. // Type: Optional
  514. //
  515. STDMETHODIMP
  516. TTYGetInfo(
  517. PDEVOBJ pdevobj,
  518. DWORD dwInfoIndex,
  519. PVOID pOutputBuf,
  520. DWORD dwSize,
  521. DWORD *pcbcNeeded)
  522. {
  523. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  524. return E_NOTIMPL;
  525. }
  526. //
  527. // Constructors
  528. //
  529. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  530. ~IOemCB() { };
  531. protected:
  532. IPrintOemDriverUni* pOEMHelp;
  533. LONG m_cRef;
  534. };
  535. //
  536. // Class factory definition
  537. //
  538. class IOemCF : public IClassFactory
  539. {
  540. public:
  541. //
  542. // IUnknown methods
  543. //
  544. STDMETHODIMP
  545. QueryInterface(const IID& iid, void** ppv)
  546. {
  547. if (ppv == NULL) return E_NOINTERFACE;
  548. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  549. {
  550. *ppv = static_cast<IOemCF*>(this);
  551. }
  552. else
  553. {
  554. *ppv = NULL ;
  555. return E_NOINTERFACE ;
  556. }
  557. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  558. return S_OK ;
  559. }
  560. STDMETHODIMP_(ULONG)
  561. AddRef()
  562. {
  563. return InterlockedIncrement(&m_cRef);
  564. }
  565. STDMETHODIMP_(ULONG)
  566. Release()
  567. {
  568. if (InterlockedDecrement(&m_cRef) == 0)
  569. {
  570. delete this ;
  571. return 0 ;
  572. }
  573. return m_cRef ;
  574. }
  575. //
  576. // IClassFactory methods
  577. //
  578. STDMETHODIMP
  579. CreateInstance(
  580. IUnknown *pUnknownOuter,
  581. const IID &iid,
  582. void **ppv)
  583. {
  584. //VERBOSE((DLLTEXT("IOemCF::CreateInstance() called\n.")));
  585. // Cannot aggregate.
  586. if (NULL != pUnknownOuter) {
  587. return CLASS_E_NOAGGREGATION;
  588. }
  589. // Create component.
  590. IOemCB* pOemCB = new IOemCB;
  591. if (NULL == pOemCB) {
  592. return E_OUTOFMEMORY;
  593. }
  594. // Get the requested interface.
  595. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  596. // Release the IUnknown pointer.
  597. // (If QueryInterface failed, component will delete itself.)
  598. pOemCB->Release();
  599. return hr ;
  600. }
  601. // LockServer
  602. STDMETHODIMP
  603. LockServer(BOOL bLock)
  604. {
  605. if (bLock)
  606. {
  607. InterlockedIncrement(&g_cServerLocks);
  608. }
  609. else
  610. {
  611. InterlockedDecrement(&g_cServerLocks);
  612. }
  613. return S_OK ;
  614. }
  615. //
  616. // Constructor
  617. //
  618. IOemCF(): m_cRef(1) { };
  619. ~IOemCF() { };
  620. protected:
  621. LONG m_cRef;
  622. };
  623. //
  624. // Export functions
  625. //
  626. //
  627. // Get class factory
  628. //
  629. STDAPI
  630. DllGetClassObject(
  631. const CLSID &clsid,
  632. const IID &iid,
  633. void **ppv)
  634. {
  635. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  636. // Can we create this component?
  637. if (clsid != CLSID_OEMRENDER)
  638. {
  639. return CLASS_E_CLASSNOTAVAILABLE ;
  640. }
  641. // Create class factory.
  642. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  643. // in constructor
  644. if (pFontCF == NULL)
  645. {
  646. return E_OUTOFMEMORY ;
  647. }
  648. // Get requested interface.
  649. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  650. pFontCF->Release();
  651. return hr ;
  652. }
  653. //
  654. //
  655. // Can DLL unload now?
  656. //
  657. STDAPI
  658. DllCanUnloadNow()
  659. {
  660. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  661. {
  662. return S_OK;
  663. }
  664. else
  665. {
  666. return S_FALSE;
  667. }
  668. }