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
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. // NOTICE-2002/3/11-takashim
  12. // 98/4/24 takashim:
  13. Written the original sample so that it is more C++.
  14. --*/
  15. // NTRAID#NTBUG9-588579-2002/03/28-v-sueyas-: Correct the return values for each COM I/F methods
  16. #define INITGUID // for GUID one-time initialization
  17. #include "pdev.h"
  18. #include "names.h"
  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. 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. // Get Interface to Helper Functions.
  225. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUni, (void** )&(this->pOEMHelp));
  226. if(!SUCCEEDED(hResult))
  227. {
  228. // Make sure that interface pointer reflects interface query failure.
  229. this->pOEMHelp = NULL;
  230. return E_FAIL;
  231. }
  232. }
  233. // Sep.8.98 <-
  234. return S_OK;
  235. }
  236. //
  237. // Function Name: GetImplementationMethod
  238. // Plug-in: Rendering module
  239. // Driver: Any
  240. // Type: Mandatory
  241. //
  242. //
  243. // Needed to be static so that it can be passed
  244. // to the bsearch() as a pointer to a functin.
  245. //
  246. static
  247. int __cdecl
  248. iCompNames(
  249. const void *p1,
  250. const void *p2) {
  251. return strcmp(
  252. (NULL == p1 ? "" : *((char **)p1)),
  253. (NULL == p2 ? "" : *((char **)p2)));
  254. }
  255. STDMETHODIMP
  256. GetImplementedMethod(
  257. PSTR pMethodName)
  258. {
  259. HRESULT hRet = E_NOTIMPL;
  260. PSTR pTemp;
  261. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  262. if (SUCCEEDED(StringCchLengthA(
  263. pMethodName, MAX_METHODNAME, NULL))) {
  264. pTemp = (PSTR)bsearch(
  265. &pMethodName,
  266. gMethodsSupported,
  267. (sizeof (gMethodsSupported) / sizeof (PSTR)),
  268. sizeof (PSTR),
  269. iCompNames);
  270. if (NULL != pTemp)
  271. hRet = S_OK;
  272. }
  273. VERBOSE((DLLTEXT("pMethodName = %s, hRet = %d\n"), pMethodName, hRet));
  274. return hRet;
  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. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  292. // SECURITY:#553895: Mandatory changes (e.g. strsafe.h)
  293. if (*piResult >= 0)
  294. return S_OK;
  295. else
  296. return E_FAIL;
  297. }
  298. //
  299. // Function Name: ImageProcessing
  300. // Plug-in: Rendering module
  301. // Driver: Unidrv
  302. // Type: Optional
  303. //
  304. STDMETHODIMP
  305. ImageProcessing(
  306. PDEVOBJ pdevobj,
  307. PBYTE pSrcBitmap,
  308. PBITMAPINFOHEADER pBitmapInfoHeader,
  309. PBYTE pColorTable,
  310. DWORD dwCallbackID,
  311. PIPPARAMS pIPParams,
  312. OUT PBYTE *ppbResult)
  313. {
  314. VERBOSE((DLLTEXT("IOemCB::ImageProcessing() entry.\n")));
  315. return E_NOTIMPL;
  316. }
  317. //
  318. // Function Name: FilterGraphics
  319. // Plug-in: Rendering module
  320. // Driver: Unidrv
  321. // Type: Optional
  322. //
  323. STDMETHODIMP
  324. FilterGraphics(
  325. PDEVOBJ pdevobj,
  326. PBYTE pBuf,
  327. DWORD dwLen)
  328. {
  329. VERBOSE((DLLTEXT("IOemCB::FilterGraphis() entry.\n")));
  330. return E_NOTIMPL;
  331. }
  332. //
  333. // Function Name: Compression
  334. // Plug-in: Rendering module
  335. // Driver: Unidrv
  336. // Type: Optional
  337. //
  338. STDMETHODIMP
  339. Compression(
  340. PDEVOBJ pdevobj,
  341. PBYTE pInBuf,
  342. PBYTE pOutBuf,
  343. DWORD dwInLen,
  344. DWORD dwOutLen,
  345. OUT INT *piResult)
  346. {
  347. VERBOSE((DLLTEXT("IOemCB::Compression() entry.\n")));
  348. return E_NOTIMPL;
  349. }
  350. //
  351. // Function Name: HalftonePattern
  352. // Plug-in: Rendering module
  353. // Driver: Unidrv
  354. // Type: Optional
  355. //
  356. STDMETHODIMP
  357. HalftonePattern(
  358. PDEVOBJ pdevobj,
  359. PBYTE pHTPattern,
  360. DWORD dwHTPatternX,
  361. DWORD dwHTPatternY,
  362. DWORD dwHTNumPatterns,
  363. DWORD dwCallbackID,
  364. PBYTE pResource,
  365. DWORD dwResourceSize)
  366. {
  367. VERBOSE((DLLTEXT("IOemCB::HalftonePattern() entry.\n")));
  368. return E_NOTIMPL;
  369. }
  370. //
  371. // Function Name: MemoryUsge
  372. // Plug-in: Rendering module
  373. // Driver: Unidrv
  374. // Type: Optional
  375. //
  376. STDMETHODIMP
  377. MemoryUsage(
  378. PDEVOBJ pdevobj,
  379. POEMMEMORYUSAGE pMemoryUsage)
  380. {
  381. VERBOSE((DLLTEXT("IOemCB::MemoryUsage() entry.\n")));
  382. return E_NOTIMPL;
  383. }
  384. //
  385. // Function Name: DownloadFontHeader
  386. // Plug-in: Rendering module
  387. // Driver: Unidrv
  388. // Type: Optional
  389. //
  390. STDMETHODIMP
  391. DownloadFontHeader(
  392. PDEVOBJ pdevobj,
  393. PUNIFONTOBJ pUFObj,
  394. OUT DWORD *pdwResult)
  395. {
  396. VERBOSE((DLLTEXT("IOemCB::DownloadFontHeader() entry.\n")));
  397. return E_NOTIMPL;
  398. }
  399. //
  400. // Function Name: DownloadCharGlyph
  401. // Plug-in: Rendering module
  402. // Driver: Unidrv
  403. // Type: Optional
  404. //
  405. STDMETHODIMP
  406. DownloadCharGlyph(
  407. PDEVOBJ pdevobj,
  408. PUNIFONTOBJ pUFObj,
  409. HGLYPH hGlyph,
  410. PDWORD pdwWidth,
  411. OUT DWORD *pdwResult)
  412. {
  413. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  414. return E_NOTIMPL;
  415. }
  416. //
  417. // Function Name: TTDonwloadMethod
  418. // Plug-in: Rendering module
  419. // Driver: Unidrv
  420. // Type: Optional
  421. //
  422. STDMETHODIMP
  423. TTDownloadMethod(
  424. PDEVOBJ pdevobj,
  425. PUNIFONTOBJ pUFObj,
  426. OUT DWORD *pdwResult)
  427. {
  428. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  429. return E_NOTIMPL;
  430. }
  431. //
  432. // Function Name: OutputCharStr
  433. // Plug-in: Rendering module
  434. // Driver: Unidrv
  435. // Type: Optional
  436. //
  437. STDMETHODIMP
  438. OutputCharStr(
  439. PDEVOBJ pdevobj,
  440. PUNIFONTOBJ pUFObj,
  441. DWORD dwType,
  442. DWORD dwCount,
  443. PVOID pGlyph)
  444. {
  445. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  446. return E_NOTIMPL;
  447. }
  448. //
  449. // Function Name: SendFontCmd
  450. // Plug-in: Rendering module
  451. // Driver: Unidrv
  452. // Type: Optional
  453. //
  454. STDMETHODIMP
  455. SendFontCmd(
  456. PDEVOBJ pdevobj,
  457. PUNIFONTOBJ pUFObj,
  458. PFINVOCATION pFInv)
  459. {
  460. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  461. return E_NOTIMPL;
  462. }
  463. //
  464. // Function Name: DriverDMS
  465. // Plug-in: Rendering module
  466. // Driver: Unidrv
  467. // Type: Optional
  468. //
  469. STDMETHODIMP
  470. DriverDMS(
  471. PVOID pDevObj,
  472. PVOID pBuffer,
  473. DWORD cbSize,
  474. PDWORD pcbNeeded)
  475. {
  476. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  477. return E_NOTIMPL;
  478. }
  479. //
  480. // Function Name: TextOutputAsBitmap
  481. // Plug-in: Rendering module
  482. // Driver: Unidrv
  483. // Type: Optional
  484. //
  485. STDMETHODIMP
  486. TextOutAsBitmap(
  487. SURFOBJ *pso,
  488. STROBJ *pstro,
  489. FONTOBJ *pfo,
  490. CLIPOBJ *pco,
  491. RECTL *prclExtra,
  492. RECTL *prclOpaque,
  493. BRUSHOBJ *pboFore,
  494. BRUSHOBJ *pboOpaque,
  495. POINTL *pptlOrg,
  496. MIX mix)
  497. {
  498. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  499. return E_NOTIMPL;
  500. }
  501. //
  502. // Function Name: TTYGetInfo
  503. // Plug-in: Rendering module
  504. // Driver: Unidrv
  505. // Type: Optional
  506. //
  507. STDMETHODIMP
  508. TTYGetInfo(
  509. PDEVOBJ pdevobj,
  510. DWORD dwInfoIndex,
  511. PVOID pOutputBuf,
  512. DWORD dwSize,
  513. DWORD *pcbcNeeded)
  514. {
  515. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  516. return E_NOTIMPL;
  517. }
  518. //
  519. // Constructors
  520. //
  521. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  522. ~IOemCB() { };
  523. protected:
  524. IPrintOemDriverUni* pOEMHelp;
  525. LONG m_cRef;
  526. };
  527. //
  528. // Class factory definition
  529. //
  530. class IOemCF : public IClassFactory
  531. {
  532. public:
  533. //
  534. // IUnknown methods
  535. //
  536. STDMETHODIMP
  537. QueryInterface(const IID& iid, void** ppv)
  538. {
  539. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  540. {
  541. *ppv = static_cast<IOemCF*>(this);
  542. }
  543. else
  544. {
  545. *ppv = NULL ;
  546. return E_NOINTERFACE ;
  547. }
  548. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  549. return S_OK ;
  550. }
  551. STDMETHODIMP_(ULONG)
  552. AddRef()
  553. {
  554. return InterlockedIncrement(&m_cRef);
  555. }
  556. STDMETHODIMP_(ULONG)
  557. Release()
  558. {
  559. if (InterlockedDecrement(&m_cRef) == 0)
  560. {
  561. delete this ;
  562. return 0 ;
  563. }
  564. return m_cRef ;
  565. }
  566. //
  567. // IClassFactory methods
  568. //
  569. STDMETHODIMP
  570. CreateInstance(
  571. IUnknown *pUnknownOuter,
  572. const IID &iid,
  573. void **ppv)
  574. {
  575. //VERBOSE((DLLTEXT("IOemCF::CreateInstance() called\n.")));
  576. // Cannot aggregate.
  577. if (NULL != pUnknownOuter) {
  578. return CLASS_E_NOAGGREGATION;
  579. }
  580. // Create component.
  581. IOemCB* pOemCB = new IOemCB;
  582. if (NULL == pOemCB) {
  583. return E_OUTOFMEMORY;
  584. }
  585. // Get the requested interface.
  586. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  587. // Release the IUnknown pointer.
  588. // (If QueryInterface failed, component will delete itself.)
  589. pOemCB->Release();
  590. return hr ;
  591. }
  592. // LockServer
  593. STDMETHODIMP
  594. LockServer(BOOL bLock)
  595. {
  596. if (bLock)
  597. {
  598. InterlockedIncrement(&g_cServerLocks);
  599. }
  600. else
  601. {
  602. InterlockedDecrement(&g_cServerLocks);
  603. }
  604. return S_OK ;
  605. }
  606. //
  607. // Constructor
  608. //
  609. IOemCF(): m_cRef(1) { };
  610. ~IOemCF() { };
  611. protected:
  612. LONG m_cRef;
  613. };
  614. //
  615. // Export functions
  616. //
  617. //
  618. // Get class factory
  619. //
  620. STDAPI
  621. DllGetClassObject(
  622. const CLSID &clsid,
  623. const IID &iid,
  624. void **ppv)
  625. {
  626. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  627. // Can we create this component?
  628. if (clsid != CLSID_OEMRENDER)
  629. {
  630. return CLASS_E_CLASSNOTAVAILABLE ;
  631. }
  632. // Create class factory.
  633. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  634. // in constructor
  635. if (pFontCF == NULL)
  636. {
  637. return E_OUTOFMEMORY ;
  638. }
  639. // Get requested interface.
  640. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  641. pFontCF->Release();
  642. return hr ;
  643. }
  644. //
  645. //
  646. // Can DLL unload now?
  647. //
  648. STDAPI
  649. DllCanUnloadNow()
  650. {
  651. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  652. {
  653. return S_OK;
  654. }
  655. else
  656. {
  657. return S_FALSE;
  658. }
  659. }