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.

785 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-588585-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((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. 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((DLLTEXT("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((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. *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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("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((DLLTEXT("IOemCB::DownloadFontHeader() entry.\n")));
  402. return E_NOTIMPL;
  403. }
  404. //
  405. // Function Name: DownloadCharGlyph
  406. // Plug-in: Rendering module
  407. // Driver: Unidrv
  408. // Type: Optional
  409. //
  410. STDMETHODIMP
  411. DownloadCharGlyph(
  412. PDEVOBJ pdevobj,
  413. PUNIFONTOBJ pUFObj,
  414. HGLYPH hGlyph,
  415. PDWORD pdwWidth,
  416. OUT DWORD *pdwResult)
  417. {
  418. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  419. return E_NOTIMPL;
  420. }
  421. //
  422. // Function Name: TTDonwloadMethod
  423. // Plug-in: Rendering module
  424. // Driver: Unidrv
  425. // Type: Optional
  426. //
  427. STDMETHODIMP
  428. TTDownloadMethod(
  429. PDEVOBJ pdevobj,
  430. PUNIFONTOBJ pUFObj,
  431. OUT DWORD *pdwResult)
  432. {
  433. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  434. return E_NOTIMPL;
  435. }
  436. //
  437. // Function Name: OutputCharStr
  438. // Plug-in: Rendering module
  439. // Driver: Unidrv
  440. // Type: Optional
  441. //
  442. STDMETHODIMP
  443. OutputCharStr(
  444. PDEVOBJ pdevobj,
  445. PUNIFONTOBJ pUFObj,
  446. DWORD dwType,
  447. DWORD dwCount,
  448. PVOID pGlyph)
  449. {
  450. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  451. return E_NOTIMPL;
  452. }
  453. //
  454. // Function Name: SendFontCmd
  455. // Plug-in: Rendering module
  456. // Driver: Unidrv
  457. // Type: Optional
  458. //
  459. STDMETHODIMP
  460. SendFontCmd(
  461. PDEVOBJ pdevobj,
  462. PUNIFONTOBJ pUFObj,
  463. PFINVOCATION pFInv)
  464. {
  465. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  466. return E_NOTIMPL;
  467. }
  468. //
  469. // Function Name: DriverDMS
  470. // Plug-in: Rendering module
  471. // Driver: Unidrv
  472. // Type: Optional
  473. //
  474. STDMETHODIMP
  475. DriverDMS(
  476. PVOID pDevObj,
  477. PVOID pBuffer,
  478. DWORD cbSize,
  479. PDWORD pcbNeeded)
  480. {
  481. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  482. return E_NOTIMPL;
  483. }
  484. //
  485. // Function Name: TextOutputAsBitmap
  486. // Plug-in: Rendering module
  487. // Driver: Unidrv
  488. // Type: Optional
  489. //
  490. STDMETHODIMP
  491. TextOutAsBitmap(
  492. SURFOBJ *pso,
  493. STROBJ *pstro,
  494. FONTOBJ *pfo,
  495. CLIPOBJ *pco,
  496. RECTL *prclExtra,
  497. RECTL *prclOpaque,
  498. BRUSHOBJ *pboFore,
  499. BRUSHOBJ *pboOpaque,
  500. POINTL *pptlOrg,
  501. MIX mix)
  502. {
  503. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  504. return E_NOTIMPL;
  505. }
  506. //
  507. // Function Name: TTYGetInfo
  508. // Plug-in: Rendering module
  509. // Driver: Unidrv
  510. // Type: Optional
  511. //
  512. STDMETHODIMP
  513. TTYGetInfo(
  514. PDEVOBJ pdevobj,
  515. DWORD dwInfoIndex,
  516. PVOID pOutputBuf,
  517. DWORD dwSize,
  518. DWORD *pcbcNeeded)
  519. {
  520. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  521. return E_NOTIMPL;
  522. }
  523. //
  524. // Constructors
  525. //
  526. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  527. ~IOemCB() { };
  528. protected:
  529. IPrintOemDriverUni* pOEMHelp;
  530. LONG m_cRef;
  531. };
  532. //
  533. // Class factory definition
  534. //
  535. class IOemCF : public IClassFactory
  536. {
  537. public:
  538. //
  539. // IUnknown methods
  540. //
  541. STDMETHODIMP
  542. QueryInterface(const IID& iid, void** ppv)
  543. {
  544. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  545. {
  546. *ppv = static_cast<IOemCF*>(this);
  547. }
  548. else
  549. {
  550. *ppv = NULL ;
  551. return E_NOINTERFACE ;
  552. }
  553. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  554. return S_OK ;
  555. }
  556. STDMETHODIMP_(ULONG)
  557. AddRef()
  558. {
  559. return InterlockedIncrement(&m_cRef);
  560. }
  561. STDMETHODIMP_(ULONG)
  562. Release()
  563. {
  564. if (InterlockedDecrement(&m_cRef) == 0)
  565. {
  566. delete this ;
  567. return 0 ;
  568. }
  569. return m_cRef ;
  570. }
  571. //
  572. // IClassFactory methods
  573. //
  574. STDMETHODIMP
  575. CreateInstance(
  576. IUnknown *pUnknownOuter,
  577. const IID &iid,
  578. void **ppv)
  579. {
  580. //VERBOSE((DLLTEXT("IOemCF::CreateInstance() called\n.")));
  581. // Cannot aggregate.
  582. if (NULL != pUnknownOuter) {
  583. return CLASS_E_NOAGGREGATION;
  584. }
  585. // Create component.
  586. IOemCB* pOemCB = new IOemCB;
  587. if (NULL == pOemCB) {
  588. return E_OUTOFMEMORY;
  589. }
  590. // Get the requested interface.
  591. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  592. // Release the IUnknown pointer.
  593. // (If QueryInterface failed, component will delete itself.)
  594. pOemCB->Release();
  595. return hr ;
  596. }
  597. // LockServer
  598. STDMETHODIMP
  599. LockServer(BOOL bLock)
  600. {
  601. if (bLock)
  602. {
  603. InterlockedIncrement(&g_cServerLocks);
  604. }
  605. else
  606. {
  607. InterlockedDecrement(&g_cServerLocks);
  608. }
  609. return S_OK ;
  610. }
  611. //
  612. // Constructor
  613. //
  614. IOemCF(): m_cRef(1) { };
  615. ~IOemCF() { };
  616. protected:
  617. LONG m_cRef;
  618. };
  619. //
  620. // Export functions
  621. //
  622. //
  623. // Get class factory
  624. //
  625. STDAPI
  626. DllGetClassObject(
  627. const CLSID &clsid,
  628. const IID &iid,
  629. void **ppv)
  630. {
  631. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  632. // Can we create this component?
  633. if (clsid != CLSID_OEMRENDER)
  634. {
  635. return CLASS_E_CLASSNOTAVAILABLE ;
  636. }
  637. // Create class factory.
  638. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  639. // in constructor
  640. if (pFontCF == NULL)
  641. {
  642. return E_OUTOFMEMORY ;
  643. }
  644. // Get requested interface.
  645. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  646. pFontCF->Release();
  647. return hr ;
  648. }
  649. //
  650. //
  651. // Can DLL unload now?
  652. //
  653. STDAPI
  654. DllCanUnloadNow()
  655. {
  656. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  657. {
  658. return S_OK;
  659. }
  660. else
  661. {
  662. return S_FALSE;
  663. }
  664. }