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.

775 lines
15 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. comoem.cpp
  5. Abstract:
  6. Environment:
  7. Windows NT Unidrv driver
  8. Revision History:
  9. Created it.
  10. --*/
  11. // NTRAID#NTBUG9-553877-2002/02/28-yasuho-: Security: mandatory changes
  12. // NTRAID#NTBUG9-576661-2002/03/14-yasuho-: Remove the dead codes
  13. // NTRAID#NTBUG9-588563-2002/03/28-v-sueyas-: Correct the return values for each COM I/F methods
  14. #define INITGUID // for GUID one-time initialization
  15. #include "pdev.h"
  16. #include "names.h"
  17. // Globals
  18. static HMODULE g_hModule = NULL ; // DLL module handle
  19. static long g_cComponents = 0 ; // Count of active components
  20. static long g_cServerLocks = 0 ; // Count of locks
  21. //
  22. // IOemCB Definition
  23. //
  24. class IOemCB : public IPrintOemUni
  25. {
  26. public:
  27. //
  28. // IUnknown methods
  29. //
  30. STDMETHODIMP
  31. QueryInterface(
  32. const IID& iid,
  33. 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. STDMETHODIMP
  76. DevMode(
  77. DWORD dwMode,
  78. POEMDMPARAM pOemDMParam)
  79. {
  80. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  81. if (OEMDevMode(dwMode, pOemDMParam)) {
  82. return S_OK;
  83. }
  84. else {
  85. return E_FAIL;
  86. }
  87. }
  88. STDMETHODIMP
  89. GetInfo(
  90. DWORD dwMode,
  91. PVOID pBuffer,
  92. DWORD cbSize,
  93. PDWORD pcbNeeded)
  94. {
  95. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  96. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  97. return S_OK;
  98. else
  99. return E_FAIL;
  100. }
  101. //
  102. // IPrintOemEngine methods
  103. //
  104. STDMETHODIMP
  105. EnableDriver(
  106. DWORD dwDriverVersion,
  107. DWORD cbSize,
  108. PDRVENABLEDATA pded)
  109. {
  110. VERBOSE((DLLTEXT("IOemCB::EnableDriver() entry.\n")));
  111. // Sep.17.98 ->
  112. // Need to return S_OK so that DisableDriver() will be called, which Releases
  113. // the reference to the Printer Driver's interface.
  114. return S_OK;
  115. // Sep.17.98 <-
  116. }
  117. //
  118. // Function Name: DisableDriver
  119. // Plug-in: Rendering module
  120. // Driver: Any
  121. // Type: Optional
  122. //
  123. STDMETHODIMP
  124. DisableDriver(VOID)
  125. {
  126. VERBOSE((DLLTEXT("IOemCB::DisaleDriver() entry.\n")));
  127. // Sep.17.98 ->
  128. // OEMDisableDriver();
  129. // Release reference to Printer Driver's interface.
  130. if (this->pOEMHelp)
  131. {
  132. this->pOEMHelp->Release();
  133. this->pOEMHelp = NULL;
  134. }
  135. return S_OK;
  136. // Sep.17.98 <-
  137. }
  138. //
  139. // Function Name: EnablePDEV
  140. // Plug-in: Rendering module
  141. // Driver: Any
  142. // Type: Optional
  143. //
  144. STDMETHODIMP
  145. EnablePDEV(
  146. PDEVOBJ pdevobj,
  147. PWSTR pPrinterName,
  148. ULONG cPatterns,
  149. HSURF *phsurfPatterns,
  150. ULONG cjGdiInfo,
  151. GDIINFO *pGdiInfo,
  152. ULONG cjDevInfo,
  153. DEVINFO *pDevInfo,
  154. DRVENABLEDATA *pded,
  155. OUT PDEVOEM *pDevOem)
  156. {
  157. VERBOSE((DLLTEXT("IOemCB::EnablePDEV() entry.\n")));
  158. PDEVOEM pTemp;
  159. pTemp = OEMEnablePDEV(pdevobj,
  160. pPrinterName, cPatterns, phsurfPatterns,
  161. cjGdiInfo, pGdiInfo, cjDevInfo, pDevInfo, pded);
  162. if (NULL == pTemp) {
  163. return E_FAIL;
  164. }
  165. //
  166. // Save necessary helpder function addresses.
  167. //
  168. ((MINIDEV *)pTemp)->pIntf = this->pOEMHelp;
  169. *pDevOem = pTemp;
  170. return S_OK;
  171. }
  172. //
  173. // Function Name: DisablePDEV
  174. // Plug-in: Rendering module
  175. // Driver: Any
  176. // Type: Optional
  177. //
  178. STDMETHODIMP
  179. DisablePDEV(
  180. PDEVOBJ pdevobj)
  181. {
  182. VERBOSE((DLLTEXT("IOemCB::DisablePDEV() entry.\n")));
  183. OEMDisablePDEV(pdevobj);
  184. return S_OK;
  185. }
  186. //
  187. // Function Name: ResetPDEV
  188. // Plug-in: Rendering module
  189. // Driver: Any
  190. // Type: Optional
  191. //
  192. STDMETHODIMP
  193. ResetPDEV(
  194. PDEVOBJ pdevobjOld,
  195. PDEVOBJ pdevobjNew)
  196. {
  197. VERBOSE((DLLTEXT("IOemCB::ResetPDEV() entry.\n")));
  198. if (OEMResetPDEV(pdevobjOld, pdevobjNew)) {
  199. return S_OK;
  200. }
  201. else {
  202. return E_FAIL;
  203. }
  204. }
  205. //
  206. // IPrintOemUni methods
  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. static
  237. int __cdecl
  238. iCompNames(
  239. const void *p1,
  240. const void *p2) {
  241. return strcmp(
  242. *((char **)p1),
  243. *((char **)p2));
  244. }
  245. STDMETHODIMP
  246. GetImplementedMethod(
  247. PSTR pMethodName)
  248. {
  249. LONG lRet = E_NOTIMPL;
  250. PSTR pTemp;
  251. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  252. if (NULL != pMethodName) {
  253. pTemp = (PSTR)bsearch(
  254. &pMethodName,
  255. gMethodsSupported,
  256. (sizeof (gMethodsSupported) / sizeof (PSTR)),
  257. sizeof (PSTR),
  258. iCompNames);
  259. if (NULL != pTemp)
  260. lRet = S_OK;
  261. }
  262. VERBOSE((DLLTEXT("pMethodName = %s, lRet = %d\n"), pMethodName, lRet));
  263. return lRet;
  264. }
  265. //
  266. // Function Name: DriverDMS
  267. // Plug-in: Rendering module
  268. // Driver: Unidrv
  269. // Type: Optional
  270. //
  271. STDMETHODIMP
  272. DriverDMS(
  273. PVOID pDevObj,
  274. PVOID pBuffer,
  275. DWORD cbSize,
  276. PDWORD pcbNeeded)
  277. {
  278. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  279. return E_NOTIMPL;
  280. }
  281. //
  282. // Function Name: CommandCallback
  283. // Plug-in: Rendering module
  284. // Driver: Unidrv
  285. // Type: Optional
  286. //
  287. STDMETHODIMP
  288. CommandCallback(
  289. PDEVOBJ pdevobj,
  290. DWORD dwCallbackID,
  291. DWORD dwCount,
  292. PDWORD pdwParams,
  293. OUT INT *piResult)
  294. {
  295. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\n")));
  296. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  297. if (*piResult >= 0)
  298. return S_OK;
  299. else
  300. return E_FAIL;
  301. }
  302. //
  303. // Function Name: ImageProcessing
  304. // Plug-in: Rendering module
  305. // Driver: Unidrv
  306. // Type: Optional
  307. //
  308. STDMETHODIMP
  309. ImageProcessing(
  310. PDEVOBJ pdevobj,
  311. PBYTE pSrcBitmap,
  312. PBITMAPINFOHEADER pBitmapInfoHeader,
  313. PBYTE pColorTable,
  314. DWORD dwCallbackID,
  315. PIPPARAMS pIPParams,
  316. OUT PBYTE *ppbResult)
  317. {
  318. VERBOSE((DLLTEXT("IOemCB::ImageProcessing() entry.\n")));
  319. return E_NOTIMPL;
  320. }
  321. //
  322. // Function Name: FilterGraphics
  323. // Plug-in: Rendering module
  324. // Driver: Unidrv
  325. // Type: Optional
  326. //
  327. STDMETHODIMP
  328. FilterGraphics(
  329. PDEVOBJ pdevobj,
  330. PBYTE pBuf,
  331. DWORD dwLen)
  332. {
  333. if (TRUE != OEMFilterGraphics(pdevobj, pBuf, dwLen)) {
  334. return E_FAIL;
  335. }
  336. return S_OK;
  337. }
  338. //
  339. // Function Name: Compression
  340. // Plug-in: Rendering module
  341. // Driver: Unidrv
  342. // Type: Optional
  343. //
  344. STDMETHODIMP
  345. Compression(
  346. PDEVOBJ pdevobj,
  347. PBYTE pInBuf,
  348. PBYTE pOutBuf,
  349. DWORD dwInLen,
  350. DWORD dwOutLen,
  351. OUT INT *piResult)
  352. {
  353. VERBOSE((DLLTEXT("IOemCB::Compression() entry.\n")));
  354. return E_NOTIMPL;
  355. }
  356. //
  357. // Function Name: HalftonePattern
  358. // Plug-in: Rendering module
  359. // Driver: Unidrv
  360. // Type: Optional
  361. //
  362. STDMETHODIMP
  363. HalftonePattern(
  364. PDEVOBJ pdevobj,
  365. PBYTE pHTPattern,
  366. DWORD dwHTPatternX,
  367. DWORD dwHTPatternY,
  368. DWORD dwHTNumPatterns,
  369. DWORD dwCallbackID,
  370. PBYTE pResource,
  371. DWORD dwResourceSize)
  372. {
  373. VERBOSE((DLLTEXT("IOemCB::HalftonePattern() entry.\n")));
  374. return E_NOTIMPL;
  375. }
  376. //
  377. // Function Name: MemoryUsge
  378. // Plug-in: Rendering module
  379. // Driver: Unidrv
  380. // Type: Optional
  381. //
  382. STDMETHODIMP
  383. MemoryUsage(
  384. PDEVOBJ pdevobj,
  385. POEMMEMORYUSAGE pMemoryUsage)
  386. {
  387. VERBOSE((DLLTEXT("IOemCB::MemoryUsage() entry.\n")));
  388. return E_NOTIMPL;
  389. }
  390. //
  391. // Function Name: TTYGetInfo
  392. // Plug-in: Rendering module
  393. // Driver: Unidrv
  394. // Type: Optional
  395. //
  396. STDMETHODIMP
  397. TTYGetInfo(
  398. PDEVOBJ pdevobj,
  399. DWORD dwInfoIndex,
  400. PVOID pOutputBuf,
  401. DWORD dwSize,
  402. DWORD *pcbcNeeded)
  403. {
  404. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  405. return E_NOTIMPL;
  406. }
  407. //
  408. // Function Name: DownloadFontHeader
  409. // Plug-in: Rendering module
  410. // Driver: Unidrv
  411. // Type: Optional
  412. //
  413. STDMETHODIMP
  414. DownloadFontHeader(
  415. PDEVOBJ pdevobj,
  416. PUNIFONTOBJ pUFObj,
  417. OUT DWORD *pdwResult)
  418. {
  419. VERBOSE((DLLTEXT("IOemCB::DownloadFontHeader() entry.\n")));
  420. return E_NOTIMPL;
  421. }
  422. //
  423. // Function Name: DownloadCharGlyph
  424. // Plug-in: Rendering module
  425. // Driver: Unidrv
  426. // Type: Optional
  427. //
  428. STDMETHODIMP
  429. DownloadCharGlyph(
  430. PDEVOBJ pdevobj,
  431. PUNIFONTOBJ pUFObj,
  432. HGLYPH hGlyph,
  433. PDWORD pdwWidth,
  434. OUT DWORD *pdwResult)
  435. {
  436. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  437. return E_NOTIMPL;
  438. }
  439. //
  440. // Function Name: TTDonwloadMethod
  441. // Plug-in: Rendering module
  442. // Driver: Unidrv
  443. // Type: Optional
  444. //
  445. STDMETHODIMP
  446. TTDownloadMethod(
  447. PDEVOBJ pdevobj,
  448. PUNIFONTOBJ pUFObj,
  449. OUT DWORD *pdwResult)
  450. {
  451. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  452. return E_NOTIMPL;
  453. }
  454. //
  455. // Function Name: OutputCharStr
  456. // Plug-in: Rendering module
  457. // Driver: Unidrv
  458. // Type: Optional
  459. //
  460. STDMETHODIMP
  461. OutputCharStr(
  462. PDEVOBJ pdevobj,
  463. PUNIFONTOBJ pUFObj,
  464. DWORD dwType,
  465. DWORD dwCount,
  466. PVOID pGlyph)
  467. {
  468. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  469. return E_NOTIMPL;
  470. }
  471. //
  472. // Function Name: SendFontCmd
  473. // Plug-in: Rendering module
  474. // Driver: Unidrv
  475. // Type: Optional
  476. //
  477. STDMETHODIMP
  478. SendFontCmd(
  479. PDEVOBJ pdevobj,
  480. PUNIFONTOBJ pUFObj,
  481. PFINVOCATION pFInv)
  482. {
  483. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  484. return E_NOTIMPL;
  485. }
  486. //
  487. // Function Name: TextOutputAsBitmap
  488. // Plug-in: Rendering module
  489. // Driver: Unidrv
  490. // Type: Optional
  491. //
  492. STDMETHODIMP
  493. TextOutAsBitmap(
  494. SURFOBJ *pso,
  495. STROBJ *pstro,
  496. FONTOBJ *pfo,
  497. CLIPOBJ *pco,
  498. RECTL *prclExtra,
  499. RECTL *prclOpaque,
  500. BRUSHOBJ *pboFore,
  501. BRUSHOBJ *pboOpaque,
  502. POINTL *pptlOrg,
  503. MIX mix)
  504. {
  505. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  506. return E_NOTIMPL;
  507. }
  508. //
  509. // Constructors
  510. //
  511. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  512. ~IOemCB() { };
  513. protected:
  514. IPrintOemDriverUni* pOEMHelp;
  515. LONG m_cRef;
  516. };
  517. // XXXDrvWriteSpoolBuf() - Obsolete.
  518. //
  519. // Class factory definition
  520. //
  521. class IOemCF : public IClassFactory
  522. {
  523. public:
  524. //
  525. // IUnknown methods
  526. //
  527. ///////////////////////////////////////////////////////////
  528. //
  529. // Class factory body
  530. //
  531. STDMETHODIMP_(HRESULT)
  532. QueryInterface(const IID& iid, void** ppv)
  533. {
  534. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  535. {
  536. *ppv = static_cast<IOemCF*>(this);
  537. }
  538. else
  539. {
  540. *ppv = NULL ;
  541. return E_NOINTERFACE ;
  542. }
  543. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  544. return S_OK ;
  545. }
  546. STDMETHODIMP_(ULONG)
  547. AddRef()
  548. {
  549. return InterlockedIncrement(&m_cRef);
  550. }
  551. STDMETHODIMP_(ULONG)
  552. Release()
  553. {
  554. if (InterlockedDecrement(&m_cRef) == 0)
  555. {
  556. delete this ;
  557. return 0 ;
  558. }
  559. return m_cRef ;
  560. }
  561. // IClassFactory implementation
  562. STDMETHODIMP_(HRESULT)
  563. CreateInstance(
  564. IUnknown *pUnknownOuter,
  565. const IID &iid,
  566. void **ppv)
  567. {
  568. //VERBOSE((DLLTEXT("IOemCF::CreateInstance() called\n.")));
  569. // Cannot aggregate.
  570. if (NULL != pUnknownOuter) {
  571. return CLASS_E_NOAGGREGATION;
  572. }
  573. // Create component.
  574. IOemCB* pOemCB = new IOemCB;
  575. if (NULL == pOemCB) {
  576. return E_OUTOFMEMORY;
  577. }
  578. // Get the requested interface.
  579. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  580. // Release the IUnknown pointer.
  581. // (If QueryInterface failed, component will delete itself.)
  582. pOemCB->Release();
  583. return hr ;
  584. }
  585. // LockServer
  586. STDMETHODIMP_(HRESULT)
  587. LockServer(BOOL bLock)
  588. {
  589. if (bLock)
  590. {
  591. InterlockedIncrement(&g_cServerLocks);
  592. }
  593. else
  594. {
  595. InterlockedDecrement(&g_cServerLocks);
  596. }
  597. return S_OK ;
  598. }
  599. //
  600. // Constructor
  601. //
  602. IOemCF(): m_cRef(1) { };
  603. ~IOemCF() { };
  604. protected:
  605. LONG m_cRef;
  606. };
  607. ///////////////////////////////////////////////////////////
  608. //
  609. // Export functions
  610. //
  611. //
  612. // Get class factory
  613. //
  614. STDAPI
  615. DllGetClassObject(
  616. const CLSID &clsid,
  617. const IID &iid,
  618. void **ppv)
  619. {
  620. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  621. // Can we create this component?
  622. if (clsid != CLSID_OEMRENDER)
  623. {
  624. return CLASS_E_CLASSNOTAVAILABLE ;
  625. }
  626. // Create class factory.
  627. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  628. // in constructor
  629. if (pFontCF == NULL)
  630. {
  631. return E_OUTOFMEMORY ;
  632. }
  633. // Get requested interface.
  634. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  635. pFontCF->Release();
  636. return hr ;
  637. }
  638. //
  639. //
  640. // Can DLL unload now?
  641. //
  642. STDAPI
  643. DllCanUnloadNow()
  644. {
  645. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  646. {
  647. return S_OK;
  648. }
  649. else
  650. {
  651. return S_FALSE;
  652. }
  653. }