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.

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