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.

766 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. #define INITGUID // for GUID one-time initialization
  14. #include "pdev.h"
  15. #include "names.h"
  16. // Globals
  17. static HMODULE g_hModule = NULL ; // DLL module handle
  18. static long g_cComponents = 0 ; // Count of active components
  19. static long g_cServerLocks = 0 ; // Count of locks
  20. #include "comoem.h"
  21. #include <strsafe.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. if (NULL == ppv)
  30. {
  31. return E_NOINTERFACE;
  32. }
  33. if (iid == IID_IUnknown)
  34. {
  35. *ppv = static_cast<IUnknown*>(this);
  36. VERBOSE((DLLTEXT("IOemCB:Return pointer to IUnknown.\n")));
  37. }
  38. else if (iid == IID_IPrintOemUni)
  39. {
  40. *ppv = static_cast<IPrintOemUni*>(this);
  41. VERBOSE((DLLTEXT("IOemCB:Return pointer to IPrintOemUni.\n")));
  42. }
  43. else
  44. {
  45. *ppv = NULL ;
  46. VERBOSE((DLLTEXT("IOemCB:Return NULL.\n")));
  47. return E_NOINTERFACE ;
  48. }
  49. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  50. return S_OK ;
  51. }
  52. ULONG __stdcall IOemCB::AddRef()
  53. {
  54. VERBOSE((DLLTEXT("IOemCB::AddRef() entry.\n")));
  55. return InterlockedIncrement(&m_cRef);
  56. }
  57. ULONG __stdcall IOemCB::Release()
  58. {
  59. VERBOSE((DLLTEXT("IOemCB::Release() entry.\n")));
  60. if (InterlockedDecrement(&m_cRef) == 0)
  61. {
  62. delete this ;
  63. return 0 ;
  64. }
  65. return m_cRef ;
  66. }
  67. // ######################
  68. // Function Name: GetInfo
  69. // Plug-in: Any
  70. // Driver: Any
  71. // Type: Mandatory
  72. //
  73. LONG __stdcall
  74. IOemCB::GetInfo(
  75. DWORD dwMode,
  76. PVOID pBuffer,
  77. DWORD cbSize,
  78. PDWORD pcbNeeded)
  79. {
  80. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  81. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  82. return S_OK;
  83. else
  84. return E_FAIL;
  85. }
  86. // ######################
  87. //
  88. // Function Name: PublishDriverInterface
  89. // Plug-in: Rendering module
  90. // Driver: Any
  91. // Type: Mandatory
  92. //
  93. LONG __stdcall
  94. IOemCB::PublishDriverInterface(
  95. IUnknown *pIUnknown)
  96. {
  97. VERBOSE((DLLTEXT("IOemCB::PublishDriverInterface() entry.\n")));
  98. if (NULL == pIUnknown)
  99. {
  100. return E_FAIL;
  101. }
  102. // Sep.8.98 ->
  103. // Need to store pointer to Driver Helper functions, if we already haven't.
  104. if (this->pOEMHelp == NULL)
  105. {
  106. HRESULT hResult;
  107. // Get Interface to Helper Functions.
  108. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUni, (void** )&(this->pOEMHelp));
  109. if(!SUCCEEDED(hResult))
  110. {
  111. // Make sure that interface pointer reflects interface query failure.
  112. this->pOEMHelp = NULL;
  113. return E_FAIL;
  114. }
  115. }
  116. // Sep.8.98 <-
  117. return S_OK;
  118. }
  119. //
  120. // Function Name: GetImplementationMethod
  121. // Plug-in: Rendering module
  122. // Driver: Any
  123. // Type: Mandatory
  124. //
  125. int __cdecl
  126. iCompNames(
  127. void *p1,
  128. void *p2) {
  129. return strcmp(
  130. (NULL == (p1) ? "" : *((char **)p1)),
  131. (NULL == (p2) ? "" : *((char **)p2)));
  132. }
  133. LONG __stdcall
  134. IOemCB::GetImplementedMethod(
  135. PSTR pMethodName)
  136. {
  137. LONG lRet = E_NOTIMPL;
  138. PSTR pTemp;
  139. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  140. if (NULL != pMethodName) {
  141. pTemp = (PSTR)bsearch(
  142. &pMethodName,
  143. gMethodsSupported,
  144. (sizeof (gMethodsSupported) / sizeof (PSTR)),
  145. sizeof (PSTR),
  146. (int (__cdecl *)(const void *, const void *))iCompNames);
  147. if (NULL != pTemp)
  148. lRet = S_OK;
  149. }
  150. VERBOSE((DLLTEXT("pMethodName = %s, lRet = %d\n"), pMethodName, lRet));
  151. return lRet;
  152. }
  153. // #######################
  154. //
  155. // Function Name: EnableDriver
  156. // Plug-in: Rendering module
  157. // Driver: Any
  158. // Type: Optional
  159. //
  160. LONG __stdcall
  161. IOemCB::EnableDriver(
  162. DWORD dwDriverVersion,
  163. DWORD cbSize,
  164. PDRVENABLEDATA pded)
  165. {
  166. VERBOSE((DLLTEXT("IOemCB::EnableDriver() entry.\n")));
  167. // Sep.17.98 ->
  168. // Need to return S_OK so that DisableDriver() will be called, which Releases
  169. // the reference to the Printer Driver's interface.
  170. return S_OK;
  171. // Sep.17.98 <-
  172. }
  173. //
  174. // Function Name: DisableDriver
  175. // Plug-in: Rendering module
  176. // Driver: Any
  177. // Type: Optional
  178. //
  179. LONG __stdcall
  180. IOemCB::DisableDriver(VOID)
  181. {
  182. VERBOSE((DLLTEXT("IOemCB::DisaleDriver() entry.\n")));
  183. // Sep.17.98 ->
  184. // OEMDisableDriver();
  185. // Release reference to Printer Driver's interface.
  186. if (this->pOEMHelp)
  187. {
  188. this->pOEMHelp->Release();
  189. this->pOEMHelp = NULL;
  190. }
  191. return S_OK;
  192. // Sep.17.98 <-
  193. }
  194. //
  195. // Function Name: EnablePDEV
  196. // Plug-in: Rendering module
  197. // Driver: Any
  198. // Type: Optional
  199. //
  200. LONG __stdcall
  201. IOemCB::EnablePDEV(
  202. PDEVOBJ pdevobj,
  203. PWSTR pPrinterName,
  204. ULONG cPatterns,
  205. HSURF *phsurfPatterns,
  206. ULONG cjGdiInfo,
  207. GDIINFO *pGdiInfo,
  208. ULONG cjDevInfo,
  209. DEVINFO *pDevInfo,
  210. DRVENABLEDATA *pded,
  211. OUT PDEVOEM *pDevOem)
  212. {
  213. VERBOSE((DLLTEXT("IOemCB::EnablePDEV() entry.\n")));
  214. if (NULL == pDevOem)
  215. {
  216. return E_FAIL;
  217. }
  218. *pDevOem = OEMEnablePDEV(pdevobj, pPrinterName, cPatterns, phsurfPatterns,
  219. cjGdiInfo, pGdiInfo, cjDevInfo, pDevInfo, pded);
  220. if (*pDevOem)
  221. return S_OK;
  222. else
  223. return E_FAIL;
  224. }
  225. //
  226. // Function Name: DisablePDEV
  227. // Plug-in: Rendering module
  228. // Driver: Any
  229. // Type: Optional
  230. //
  231. LONG __stdcall
  232. IOemCB::DisablePDEV(
  233. PDEVOBJ pdevobj)
  234. {
  235. LONG lI;
  236. VERBOSE((DLLTEXT("IOemCB::DisablePDEV() entry.\n")));
  237. OEMDisablePDEV(pdevobj);
  238. return S_OK;
  239. }
  240. //
  241. // Function Name: ResetPDEV
  242. // Plug-in: Rendering module
  243. // Driver: Any
  244. // Type: Optional
  245. //
  246. LONG __stdcall
  247. IOemCB::ResetPDEV(
  248. PDEVOBJ pdevobjOld,
  249. PDEVOBJ pdevobjNew)
  250. {
  251. VERBOSE((DLLTEXT("IOemCB::ResetPDEV() entry.\n")));
  252. if (OEMResetPDEV(pdevobjOld, pdevobjNew))
  253. return S_OK;
  254. else
  255. return E_FAIL;
  256. }
  257. //
  258. // Function Name: DevMode
  259. // Plug-in: Rendering module
  260. // Driver: Any
  261. // Type: Optional
  262. //
  263. LONG __stdcall
  264. IOemCB::DevMode(
  265. DWORD dwMode,
  266. POEMDMPARAM pOemDMParam)
  267. {
  268. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  269. if (OEMDevMode(dwMode, pOemDMParam)) {
  270. return S_OK;
  271. }
  272. else {
  273. return E_FAIL;
  274. }
  275. }
  276. // ################
  277. //
  278. // Function Name: CommandCallback
  279. // Plug-in: Rendering module
  280. // Driver: Unidrv
  281. // Type: Optional
  282. //
  283. LONG __stdcall
  284. IOemCB::CommandCallback(
  285. PDEVOBJ pdevobj,
  286. DWORD dwCallbackID,
  287. DWORD dwCount,
  288. PDWORD pdwParams,
  289. OUT INT *piResult)
  290. {
  291. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\n")));
  292. if (NULL == piResult)
  293. {
  294. return E_FAIL;
  295. }
  296. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  297. if (*piResult < 0) {
  298. return E_FAIL;
  299. }
  300. return S_OK;
  301. }
  302. //
  303. // Function Name: ImageProcessing
  304. // Plug-in: Rendering module
  305. // Driver: Unidrv
  306. // Type: Optional
  307. //
  308. LONG __stdcall
  309. IOemCB::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. LONG __stdcall
  328. IOemCB::FilterGraphics(
  329. PDEVOBJ pdevobj,
  330. PBYTE pBuf,
  331. DWORD dwLen)
  332. {
  333. VERBOSE((DLLTEXT("IOemCB::FilterGraphis() entry.\n")));
  334. if (OEMFilterGraphics(pdevobj, pBuf, dwLen)) {
  335. return S_OK;
  336. }
  337. else {
  338. return E_FAIL;
  339. }
  340. }
  341. //
  342. // Function Name: Compression
  343. // Plug-in: Rendering module
  344. // Driver: Unidrv
  345. // Type: Optional
  346. //
  347. LONG __stdcall
  348. IOemCB::Compression(
  349. PDEVOBJ pdevobj,
  350. PBYTE pInBuf,
  351. PBYTE pOutBuf,
  352. DWORD dwInLen,
  353. DWORD dwOutLen,
  354. OUT INT *piResult)
  355. {
  356. VERBOSE((DLLTEXT("IOemCB::Compression() entry.\n")));
  357. return E_NOTIMPL;
  358. }
  359. //
  360. // Function Name: HalftonePattern
  361. // Plug-in: Rendering module
  362. // Driver: Unidrv
  363. // Type: Optional
  364. //
  365. LONG __stdcall
  366. IOemCB::HalftonePattern(
  367. PDEVOBJ pdevobj,
  368. PBYTE pHTPattern,
  369. DWORD dwHTPatternX,
  370. DWORD dwHTPatternY,
  371. DWORD dwHTNumPatterns,
  372. DWORD dwCallbackID,
  373. PBYTE pResource,
  374. DWORD dwResourceSize)
  375. {
  376. VERBOSE((DLLTEXT("IOemCB::HalftonePattern() entry.\n")));
  377. return E_NOTIMPL;
  378. }
  379. //
  380. // Function Name: MemoryUsge
  381. // Plug-in: Rendering module
  382. // Driver: Unidrv
  383. // Type: Optional
  384. //
  385. LONG __stdcall
  386. IOemCB::MemoryUsage(
  387. PDEVOBJ pdevobj,
  388. POEMMEMORYUSAGE pMemoryUsage)
  389. {
  390. VERBOSE((DLLTEXT("IOemCB::MemoryUsage() entry.\n")));
  391. return E_NOTIMPL;
  392. }
  393. //
  394. // Function Name: DownloadFontHeader
  395. // Plug-in: Rendering module
  396. // Driver: Unidrv
  397. // Type: Optional
  398. //
  399. LONG __stdcall
  400. IOemCB::DownloadFontHeader(
  401. PDEVOBJ pdevobj,
  402. PUNIFONTOBJ pUFObj,
  403. OUT DWORD *pdwResult)
  404. {
  405. VERBOSE((DLLTEXT("IOemCB::DownloadFontHeader() entry.\n")));
  406. return E_NOTIMPL;
  407. }
  408. //
  409. // Function Name: DownloadCharGlyph
  410. // Plug-in: Rendering module
  411. // Driver: Unidrv
  412. // Type: Optional
  413. //
  414. LONG __stdcall
  415. IOemCB::DownloadCharGlyph(
  416. PDEVOBJ pdevobj,
  417. PUNIFONTOBJ pUFObj,
  418. HGLYPH hGlyph,
  419. PDWORD pdwWidth,
  420. OUT DWORD *pdwResult)
  421. {
  422. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  423. return E_NOTIMPL;
  424. }
  425. //
  426. // Function Name: TTDonwloadMethod
  427. // Plug-in: Rendering module
  428. // Driver: Unidrv
  429. // Type: Optional
  430. //
  431. LONG __stdcall
  432. IOemCB::TTDownloadMethod(
  433. PDEVOBJ pdevobj,
  434. PUNIFONTOBJ pUFObj,
  435. OUT DWORD *pdwResult)
  436. {
  437. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  438. return E_NOTIMPL;
  439. }
  440. //
  441. // Function Name: OutputCharStr
  442. // Plug-in: Rendering module
  443. // Driver: Unidrv
  444. // Type: Optional
  445. //
  446. LONG __stdcall
  447. IOemCB::OutputCharStr(
  448. PDEVOBJ pdevobj,
  449. PUNIFONTOBJ pUFObj,
  450. DWORD dwType,
  451. DWORD dwCount,
  452. PVOID pGlyph)
  453. {
  454. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  455. return E_NOTIMPL;
  456. }
  457. //
  458. // Function Name: SendFontCmd
  459. // Plug-in: Rendering module
  460. // Driver: Unidrv
  461. // Type: Optional
  462. //
  463. LONG __stdcall
  464. IOemCB::SendFontCmd(
  465. PDEVOBJ pdevobj,
  466. PUNIFONTOBJ pUFObj,
  467. PFINVOCATION pFInv)
  468. {
  469. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  470. return E_NOTIMPL;
  471. }
  472. //
  473. // Function Name: DriverDMS
  474. // Plug-in: Rendering module
  475. // Driver: Unidrv
  476. // Type: Optional
  477. //
  478. LONG __stdcall
  479. IOemCB::DriverDMS(
  480. PVOID pDevObj,
  481. PVOID pBuffer,
  482. DWORD cbSize,
  483. PDWORD pcbNeeded)
  484. {
  485. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  486. return E_NOTIMPL;
  487. }
  488. //
  489. // Function Name: TextOutputAsBitmap
  490. // Plug-in: Rendering module
  491. // Driver: Unidrv
  492. // Type: Optional
  493. //
  494. LONG __stdcall
  495. IOemCB::TextOutAsBitmap(
  496. SURFOBJ *pso,
  497. STROBJ *pstro,
  498. FONTOBJ *pfo,
  499. CLIPOBJ *pco,
  500. RECTL *prclExtra,
  501. RECTL *prclOpaque,
  502. BRUSHOBJ *pboFore,
  503. BRUSHOBJ *pboOpaque,
  504. POINTL *pptlOrg,
  505. MIX mix)
  506. {
  507. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  508. return E_NOTIMPL;
  509. }
  510. //
  511. // Function Name: TTYGetInfo
  512. // Plug-in: Rendering module
  513. // Driver: Unidrv
  514. // Type: Optional
  515. //
  516. LONG __stdcall
  517. IOemCB::TTYGetInfo(
  518. PDEVOBJ pdevobj,
  519. DWORD dwInfoIndex,
  520. PVOID pOutputBuf,
  521. DWORD dwSize,
  522. DWORD *pcbcNeeded)
  523. {
  524. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  525. return E_NOTIMPL;
  526. }
  527. ///////////////////////////////////////////////////////////
  528. //
  529. // Class factory body
  530. //
  531. HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv)
  532. {
  533. if (NULL == ppv)
  534. {
  535. return E_NOINTERFACE;
  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. ULONG __stdcall IOemCF::AddRef()
  550. {
  551. return InterlockedIncrement(&m_cRef);
  552. }
  553. ULONG __stdcall IOemCF::Release()
  554. {
  555. if (InterlockedDecrement(&m_cRef) == 0)
  556. {
  557. delete this ;
  558. return 0 ;
  559. }
  560. return m_cRef ;
  561. }
  562. // IClassFactory implementation
  563. HRESULT __stdcall
  564. IOemCF::CreateInstance(
  565. IUnknown *pUnknownOuter,
  566. const IID &iid,
  567. void **ppv)
  568. {
  569. //VERBOSE((DLLTEXT("IOemCF::CreateInstance() called\n.")));
  570. // Cannot aggregate.
  571. if (NULL != pUnknownOuter) {
  572. return CLASS_E_NOAGGREGATION;
  573. }
  574. // Create component.
  575. IOemCB* pOemCB = new IOemCB;
  576. if (NULL == pOemCB) {
  577. return E_OUTOFMEMORY;
  578. }
  579. // Get the requested interface.
  580. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  581. // Release the IUnknown pointer.
  582. // (If QueryInterface failed, component will delete itself.)
  583. pOemCB->Release();
  584. return hr ;
  585. }
  586. // LockServer
  587. HRESULT __stdcall IOemCF::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. //
  601. // Export functions
  602. //
  603. //
  604. // Get class factory
  605. //
  606. STDAPI
  607. DllGetClassObject(
  608. const CLSID &clsid,
  609. const IID &iid,
  610. void **ppv)
  611. {
  612. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  613. // Can we create this component?
  614. if (clsid != CLSID_OEMRENDER)
  615. {
  616. return CLASS_E_CLASSNOTAVAILABLE ;
  617. }
  618. // Create class factory.
  619. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  620. // in constructor
  621. if (pFontCF == NULL)
  622. {
  623. return E_OUTOFMEMORY ;
  624. }
  625. // Get requested interface.
  626. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  627. pFontCF->Release();
  628. return hr ;
  629. }
  630. //
  631. //
  632. // Can DLL unload now?
  633. //
  634. STDAPI
  635. DllCanUnloadNow()
  636. {
  637. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  638. {
  639. return S_OK;
  640. }
  641. else
  642. {
  643. return S_FALSE;
  644. }
  645. }