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.

749 lines
15 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. comoem.cpp
  5. Abstract:
  6. Implementation of OEMGetInfo and OEMDevMode.
  7. Shared by all Unidrv OEM test dll's.
  8. Environment:
  9. Windows NT Unidrv driver
  10. Revision History:
  11. Created it.
  12. --*/
  13. // NTRAID#NTBUG9-588582-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. #include "comoem.h"
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //
  24. // IOemCB body
  25. //
  26. HRESULT __stdcall IOemCB::QueryInterface(const IID& iid, void** ppv)
  27. {
  28. VERBOSE((DLLTEXT("IOemCB: QueryInterface entry\n")));
  29. // NTRAID#NTBUG9-581725-2002/03/25-v-sueyas-: Check for illegal parameters
  30. if (NULL == ppv)
  31. return E_NOINTERFACE;
  32. if (iid == IID_IUnknown)
  33. {
  34. *ppv = static_cast<IUnknown*>(this);
  35. VERBOSE((DLLTEXT("IOemCB:Return pointer to IUnknown.\n")));
  36. }
  37. else if (iid == IID_IPrintOemUni)
  38. {
  39. *ppv = static_cast<IPrintOemUni*>(this);
  40. VERBOSE((DLLTEXT("IOemCB:Return pointer to IPrintOemUni.\n")));
  41. }
  42. else
  43. {
  44. *ppv = NULL ;
  45. VERBOSE((DLLTEXT("IOemCB:Return NULL.\n")));
  46. return E_NOINTERFACE ;
  47. }
  48. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  49. return S_OK ;
  50. }
  51. ULONG __stdcall IOemCB::AddRef()
  52. {
  53. VERBOSE((DLLTEXT("IOemCB::AddRef() entry.\n")));
  54. return InterlockedIncrement(&m_cRef);
  55. }
  56. ULONG __stdcall IOemCB::Release()
  57. {
  58. VERBOSE((DLLTEXT("IOemCB::Release() entry.\n")));
  59. if (InterlockedDecrement(&m_cRef) == 0)
  60. {
  61. delete this ;
  62. return 0 ;
  63. }
  64. return m_cRef ;
  65. }
  66. // ######################
  67. // Function Name: GetInfo
  68. // Plug-in: Any
  69. // Driver: Any
  70. // Type: Mandatory
  71. //
  72. LONG __stdcall
  73. IOemCB::GetInfo(
  74. DWORD dwMode,
  75. PVOID pBuffer,
  76. DWORD cbSize,
  77. PDWORD pcbNeeded)
  78. {
  79. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  80. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  81. return S_OK;
  82. else
  83. return E_FAIL;
  84. }
  85. // ######################
  86. //
  87. // Function Name: PublishDriverInterface
  88. // Plug-in: Rendering module
  89. // Driver: Any
  90. // Type: Mandatory
  91. //
  92. LONG __stdcall
  93. IOemCB::PublishDriverInterface(
  94. IUnknown *pIUnknown)
  95. {
  96. VERBOSE((DLLTEXT("IOemCB::PublishDriverInterface() entry.\n")));
  97. // Sep.8.98 ->
  98. // Need to store pointer to Driver Helper functions, if we already haven't.
  99. if (this->pOEMHelp == NULL)
  100. {
  101. HRESULT hResult;
  102. // Get Interface to Helper Functions.
  103. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUni, (void** )&(this->pOEMHelp));
  104. if(!SUCCEEDED(hResult))
  105. {
  106. // Make sure that interface pointer reflects interface query failure.
  107. this->pOEMHelp = NULL;
  108. return E_FAIL;
  109. }
  110. }
  111. // Sep.8.98 <-
  112. return S_OK;
  113. }
  114. //
  115. // Function Name: GetImplementationMethod
  116. // Plug-in: Rendering module
  117. // Driver: Any
  118. // Type: Mandatory
  119. //
  120. int __cdecl
  121. iCompNames(
  122. void *p1,
  123. void *p2) {
  124. // NTRAID#NTBUG9-581725-2002/03/25-v-sueyas-: Check for illegal parameters
  125. return strcmp(
  126. (NULL == p1 ? "" : *((char **)p1)),
  127. (NULL == p2 ? "" : *((char **)p2)));
  128. }
  129. LONG __stdcall
  130. IOemCB::GetImplementedMethod(
  131. PSTR pMethodName)
  132. {
  133. LONG lRet = E_NOTIMPL;
  134. PSTR pTemp;
  135. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  136. if (NULL != pMethodName) {
  137. pTemp = (PSTR)bsearch(
  138. &pMethodName,
  139. gMethodsSupported,
  140. (sizeof (gMethodsSupported) / sizeof (PSTR)),
  141. sizeof (PSTR),
  142. (int (__cdecl *)(const void *, const void *))iCompNames);
  143. if (NULL != pTemp)
  144. lRet = S_OK;
  145. }
  146. VERBOSE((DLLTEXT("pMethodName = %s, lRet = %d\n"), pMethodName, lRet));
  147. return lRet;
  148. }
  149. // #######################
  150. //
  151. // Function Name: EnableDriver
  152. // Plug-in: Rendering module
  153. // Driver: Any
  154. // Type: Optional
  155. //
  156. LONG __stdcall
  157. IOemCB::EnableDriver(
  158. DWORD dwDriverVersion,
  159. DWORD cbSize,
  160. PDRVENABLEDATA pded)
  161. {
  162. VERBOSE((DLLTEXT("IOemCB::EnableDriver() entry.\n")));
  163. // Sep.17.98 ->
  164. // Need to return S_OK so that DisableDriver() will be called, which Releases
  165. // the reference to the Printer Driver's interface.
  166. return S_OK;
  167. // Sep.17.98 <-
  168. }
  169. //
  170. // Function Name: DisableDriver
  171. // Plug-in: Rendering module
  172. // Driver: Any
  173. // Type: Optional
  174. //
  175. LONG __stdcall
  176. IOemCB::DisableDriver(VOID)
  177. {
  178. VERBOSE((DLLTEXT("IOemCB::DisaleDriver() entry.\n")));
  179. // Sep.17.98 ->
  180. // Release reference to Printer Driver's interface.
  181. if (this->pOEMHelp)
  182. {
  183. this->pOEMHelp->Release();
  184. this->pOEMHelp = NULL;
  185. }
  186. return S_OK;
  187. // Sep.17.98 <-
  188. }
  189. //
  190. // Function Name: EnablePDEV
  191. // Plug-in: Rendering module
  192. // Driver: Any
  193. // Type: Optional
  194. //
  195. LONG __stdcall
  196. IOemCB::EnablePDEV(
  197. PDEVOBJ pdevobj,
  198. PWSTR pPrinterName,
  199. ULONG cPatterns,
  200. HSURF *phsurfPatterns,
  201. ULONG cjGdiInfo,
  202. GDIINFO *pGdiInfo,
  203. ULONG cjDevInfo,
  204. DEVINFO *pDevInfo,
  205. DRVENABLEDATA *pded,
  206. OUT PDEVOEM *pDevOem)
  207. {
  208. VERBOSE((DLLTEXT("IOemCB::EnablePDEV() entry.\n")));
  209. // NTRAID#NTBUG9-581725-2002/03/25-v-sueyas-: Check for illegal parameters
  210. if (NULL == pDevOem)
  211. return E_FAIL;
  212. *pDevOem = OEMEnablePDEV(pdevobj, pPrinterName, cPatterns, phsurfPatterns,
  213. cjGdiInfo, pGdiInfo, cjDevInfo, pDevInfo, pded);
  214. if (*pDevOem)
  215. return S_OK;
  216. else
  217. return E_FAIL;
  218. }
  219. //
  220. // Function Name: DisablePDEV
  221. // Plug-in: Rendering module
  222. // Driver: Any
  223. // Type: Optional
  224. //
  225. LONG __stdcall
  226. IOemCB::DisablePDEV(
  227. PDEVOBJ pdevobj)
  228. {
  229. VERBOSE((DLLTEXT("IOemCB::DisablePDEV() entry.\n")));
  230. OEMDisablePDEV(pdevobj);
  231. return S_OK;
  232. }
  233. //
  234. // Function Name: ResetPDEV
  235. // Plug-in: Rendering module
  236. // Driver: Any
  237. // Type: Optional
  238. //
  239. LONG __stdcall
  240. IOemCB::ResetPDEV(
  241. PDEVOBJ pdevobjOld,
  242. PDEVOBJ pdevobjNew)
  243. {
  244. VERBOSE((DLLTEXT("IOemCB::ResetPDEV() entry.\n")));
  245. if (OEMResetPDEV(pdevobjOld, pdevobjNew))
  246. return S_OK;
  247. else
  248. return E_FAIL;
  249. }
  250. //
  251. // Function Name: DevMode
  252. // Plug-in: Rendering module
  253. // Driver: Any
  254. // Type: Optional
  255. //
  256. LONG __stdcall
  257. IOemCB::DevMode(
  258. DWORD dwMode,
  259. POEMDMPARAM pOemDMParam)
  260. {
  261. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  262. if (OEMDevMode(dwMode, pOemDMParam)) {
  263. return S_OK;
  264. }
  265. else {
  266. return E_FAIL;
  267. }
  268. }
  269. // ################
  270. //
  271. // Function Name: CommandCallback
  272. // Plug-in: Rendering module
  273. // Driver: Unidrv
  274. // Type: Optional
  275. //
  276. LONG __stdcall
  277. IOemCB::CommandCallback(
  278. PDEVOBJ pdevobj,
  279. DWORD dwCallbackID,
  280. DWORD dwCount,
  281. PDWORD pdwParams,
  282. OUT INT *piResult)
  283. {
  284. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\n")));
  285. // NTRAID#NTBUG9-581725-2002/03/25-v-sueyas-: Check for illegal parameters
  286. if (NULL == piResult)
  287. return E_FAIL;
  288. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  289. return S_OK;
  290. }
  291. //
  292. // Function Name: ImageProcessing
  293. // Plug-in: Rendering module
  294. // Driver: Unidrv
  295. // Type: Optional
  296. //
  297. LONG __stdcall
  298. IOemCB::ImageProcessing(
  299. PDEVOBJ pdevobj,
  300. PBYTE pSrcBitmap,
  301. PBITMAPINFOHEADER pBitmapInfoHeader,
  302. PBYTE pColorTable,
  303. DWORD dwCallbackID,
  304. PIPPARAMS pIPParams,
  305. OUT PBYTE *ppbResult)
  306. {
  307. VERBOSE((DLLTEXT("IOemCB::ImageProcessing() entry.\n")));
  308. return E_NOTIMPL;
  309. }
  310. //
  311. // Function Name: FilterGraphics
  312. // Plug-in: Rendering module
  313. // Driver: Unidrv
  314. // Type: Optional
  315. //
  316. LONG __stdcall
  317. IOemCB::FilterGraphics(
  318. PDEVOBJ pdevobj,
  319. PBYTE pBuf,
  320. DWORD dwLen)
  321. {
  322. VERBOSE((DLLTEXT("IOemCB::FilterGraphis() entry.\n")));
  323. if (OEMFilterGraphics(pdevobj, pBuf, dwLen)) {
  324. return S_OK;
  325. }
  326. else {
  327. return E_FAIL;
  328. }
  329. }
  330. //
  331. // Function Name: Compression
  332. // Plug-in: Rendering module
  333. // Driver: Unidrv
  334. // Type: Optional
  335. //
  336. LONG __stdcall
  337. IOemCB::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. LONG __stdcall
  355. IOemCB::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. LONG __stdcall
  375. IOemCB::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. LONG __stdcall
  389. IOemCB::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. LONG __stdcall
  404. IOemCB::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. LONG __stdcall
  421. IOemCB::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. LONG __stdcall
  436. IOemCB::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. LONG __stdcall
  453. IOemCB::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. LONG __stdcall
  468. IOemCB::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. LONG __stdcall
  484. IOemCB::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. LONG __stdcall
  506. IOemCB::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. //
  518. // Class factory body
  519. //
  520. HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv)
  521. {
  522. // NTRAID#NTBUG9-581725-2002/03/25-v-sueyas-: Check for illegal parameters
  523. if (NULL == ppv)
  524. return E_NOINTERFACE;
  525. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  526. {
  527. *ppv = static_cast<IOemCF*>(this);
  528. }
  529. else
  530. {
  531. *ppv = NULL ;
  532. return E_NOINTERFACE ;
  533. }
  534. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  535. return S_OK ;
  536. }
  537. ULONG __stdcall IOemCF::AddRef()
  538. {
  539. return InterlockedIncrement(&m_cRef);
  540. }
  541. ULONG __stdcall IOemCF::Release()
  542. {
  543. if (InterlockedDecrement(&m_cRef) == 0)
  544. {
  545. delete this ;
  546. return 0 ;
  547. }
  548. return m_cRef ;
  549. }
  550. // IClassFactory implementation
  551. HRESULT __stdcall
  552. IOemCF::CreateInstance(
  553. IUnknown *pUnknownOuter,
  554. const IID &iid,
  555. void **ppv)
  556. {
  557. // Cannot aggregate.
  558. if (NULL != pUnknownOuter) {
  559. return CLASS_E_NOAGGREGATION;
  560. }
  561. // Create component.
  562. IOemCB* pOemCB = new IOemCB;
  563. if (NULL == pOemCB) {
  564. return E_OUTOFMEMORY;
  565. }
  566. // Get the requested interface.
  567. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  568. // Release the IUnknown pointer.
  569. // (If QueryInterface failed, component will delete itself.)
  570. pOemCB->Release();
  571. return hr ;
  572. }
  573. // LockServer
  574. HRESULT __stdcall IOemCF::LockServer(BOOL bLock)
  575. {
  576. if (bLock)
  577. {
  578. InterlockedIncrement(&g_cServerLocks);
  579. }
  580. else
  581. {
  582. InterlockedDecrement(&g_cServerLocks);
  583. }
  584. return S_OK ;
  585. }
  586. ///////////////////////////////////////////////////////////
  587. //
  588. // Export functions
  589. //
  590. //
  591. // Get class factory
  592. //
  593. STDAPI
  594. DllGetClassObject(
  595. const CLSID &clsid,
  596. const IID &iid,
  597. void **ppv)
  598. {
  599. // Can we create this component?
  600. if (clsid != CLSID_OEMRENDER)
  601. {
  602. return CLASS_E_CLASSNOTAVAILABLE ;
  603. }
  604. // Create class factory.
  605. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  606. // in constructor
  607. if (pFontCF == NULL)
  608. {
  609. return E_OUTOFMEMORY ;
  610. }
  611. // Get requested interface.
  612. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  613. pFontCF->Release();
  614. return hr ;
  615. }
  616. //
  617. //
  618. // Can DLL unload now?
  619. //
  620. STDAPI
  621. DllCanUnloadNow()
  622. {
  623. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  624. {
  625. return S_OK;
  626. }
  627. else
  628. {
  629. return S_FALSE;
  630. }
  631. }