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.

967 lines
25 KiB

  1. /*++
  2. Copyright (c) 1996-2003 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 2000, Windows XP, Windows Server 2003 Unidrv driver
  10. Revision History:
  11. Created it.
  12. --*/
  13. #ifndef _WIN32_WINNT
  14. #define _WIN32_WINNT 0x0500
  15. #endif
  16. #include <tty.h>
  17. #include <printoem.h>
  18. #include <prntfont.h>
  19. #include "..\inc\name.h"
  20. #include <initguid.h>
  21. #include <prcomoem.h>
  22. #include <assert.h>
  23. #include "oemcom.h"
  24. #include "ttyui.h"
  25. #include "debug.h"
  26. #include <strsafe.h>
  27. // Globals
  28. static HMODULE g_hModule = NULL ; // DLL module handle
  29. static long g_cComponents = 0 ; // Count of active components
  30. static long g_cServerLocks = 0 ; // Count of locks
  31. ////////////////////////////////////////////////////////////////////////////////
  32. //
  33. // IOemCB body
  34. //
  35. HRESULT __stdcall IOemCB::QueryInterface(const IID& iid, void** ppv)
  36. {
  37. VERBOSE(DLLTEXT("IOemCB: QueryInterface entry\n"));
  38. if (iid == IID_IUnknown)
  39. {
  40. *ppv = static_cast<IUnknown*>(this);
  41. VERBOSE(DLLTEXT("IOemCB:Return pointer to IUnknown.\n")) ;
  42. }
  43. else if (iid == IID_IPrintOemUni2)
  44. {
  45. *ppv = static_cast<IPrintOemUni2*>(this) ;
  46. VERBOSE(DLLTEXT("IOemCB:Return pointer to IPrintOemUni.\n")) ;
  47. }
  48. else
  49. {
  50. *ppv = NULL ;
  51. WARNING(DLLTEXT("IOemCB:Return NULL.\n")) ;
  52. return E_NOINTERFACE ;
  53. }
  54. reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
  55. return S_OK ;
  56. }
  57. ULONG __stdcall IOemCB::AddRef()
  58. {
  59. VERBOSE(DLLTEXT("IOemCB::AddRef() entry.\r\n"));
  60. return InterlockedIncrement(&m_cRef) ;
  61. }
  62. ULONG __stdcall IOemCB::Release()
  63. {
  64. VERBOSE(DLLTEXT("IOemCB::Release() entry.\r\n"));
  65. ASSERT( 0 != m_cRef);
  66. ULONG cRef = InterlockedDecrement(&m_cRef);
  67. if (0 == cRef)
  68. {
  69. delete this;
  70. }
  71. return cRef;
  72. }
  73. IOemCB::~IOemCB()
  74. {
  75. //
  76. // Make sure that driver's helper function interface is released.
  77. //
  78. if(NULL != pOEMHelp)
  79. {
  80. pOEMHelp->Release();
  81. pOEMHelp = NULL;
  82. }
  83. //
  84. // If this instance of the object is being deleted, then the reference
  85. // count should be zero.
  86. //
  87. assert(0 == m_cRef) ;
  88. }
  89. LONG __stdcall IOemCB::PublishDriverInterface(
  90. IUnknown *pIUnknown)
  91. {
  92. VERBOSE(DLLTEXT("IOemCB::PublishDriverInterface() entry.\r\n"));
  93. //
  94. // Need to store pointer to Driver Helper functions, if we already haven't.
  95. //
  96. if (this->pOEMHelp == NULL)
  97. {
  98. HRESULT hResult;
  99. //
  100. // Get Interface to Helper Functions.
  101. //
  102. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUni, (void** ) &(this->pOEMHelp));
  103. if(!SUCCEEDED(hResult))
  104. {
  105. //
  106. // Make sure that interface pointer reflects interface query failure.
  107. //
  108. this->pOEMHelp = NULL;
  109. }
  110. }
  111. if (this->pOEMHelp)
  112. return S_OK;
  113. else
  114. return E_FAIL;
  115. }
  116. LONG __stdcall IOemCB::EnableDriver(DWORD dwDriverVersion,
  117. DWORD cbSize,
  118. PDRVENABLEDATA pded)
  119. {
  120. VERBOSE(DLLTEXT("IOemCB::EnableDriver() entry.\r\n"));
  121. if(OEMEnableDriver(dwDriverVersion, cbSize, pded) )
  122. return S_OK;
  123. return E_FAIL;
  124. }
  125. LONG __stdcall IOemCB::DisableDriver(VOID)
  126. {
  127. VERBOSE(DLLTEXT("IOemCB::DisaleDriver() entry.\r\n"));
  128. if (this->pOEMHelp)
  129. {
  130. this->pOEMHelp->Release();
  131. this->pOEMHelp = NULL ;
  132. }
  133. return S_OK;
  134. }
  135. // the following OEM function is called by Unidrv to provide
  136. // the OEM dll with an interface it can use to access Unidrv's
  137. // helper functions like WriteSpoolBuf etc.
  138. // warning: calling this more per IOemCB object than once will result
  139. // in mismatched reference counts.
  140. LONG __stdcall IOemCB::EnablePDEV(
  141. PDEVOBJ pdevobj,
  142. PWSTR pPrinterName,
  143. ULONG cPatterns,
  144. HSURF *phsurfPatterns,
  145. ULONG cjGdiInfo,
  146. GDIINFO *pGdiInfo,
  147. ULONG cjDevInfo,
  148. DEVINFO *pDevInfo,
  149. DRVENABLEDATA *pded,
  150. OUT PDEVOEM *ppDevOem)
  151. {
  152. VERBOSE(DLLTEXT("IOemCB::EnablePDEV() entry.\r\n"));
  153. if(*ppDevOem = OEMEnablePDEV(pdevobj, pPrinterName, cPatterns,
  154. phsurfPatterns, cjGdiInfo, pGdiInfo, cjDevInfo, pDevInfo, pded) )
  155. return S_OK;
  156. return E_FAIL;
  157. }
  158. LONG __stdcall IOemCB::ResetPDEV(
  159. PDEVOBJ pdevobjOld,
  160. PDEVOBJ pdevobjNew)
  161. {
  162. return E_NOTIMPL;
  163. }
  164. LONG __stdcall IOemCB::DisablePDEV(
  165. PDEVOBJ pdevobj)
  166. {
  167. VERBOSE(DLLTEXT("IOemCB::DisablePDEV() entry.\r\n"));
  168. OEMDisablePDEV(pdevobj) ;
  169. return S_OK;
  170. };
  171. LONG __stdcall IOemCB::GetInfo (
  172. DWORD dwMode,
  173. PVOID pBuffer,
  174. DWORD cbSize,
  175. PDWORD pcbNeeded)
  176. {
  177. VERBOSE(DLLTEXT("IOemCB::GetInfo() entry.\r\n"));
  178. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  179. return S_OK;
  180. else
  181. return E_FAIL;
  182. }
  183. LONG __stdcall IOemCB::GetImplementedMethod(
  184. PSTR pMethodName)
  185. {
  186. LONG lReturn = FALSE;
  187. VERBOSE(DLLTEXT("IOemCB::GetImplementedMethod() entry.\r\n"));
  188. VERBOSE(DLLTEXT(" Function:%s:"),pMethodName);
  189. if (pMethodName == NULL)
  190. {
  191. lReturn = FALSE;
  192. }
  193. else
  194. {
  195. switch (*pMethodName)
  196. {
  197. case (WCHAR)'C':
  198. if (!strcmp(pstrCommandCallback, pMethodName))
  199. lReturn = TRUE;
  200. #if 0
  201. else if (!strcmp(pstrCompression, pMethodName))
  202. lReturn = TRUE;
  203. #endif
  204. break;
  205. case (WCHAR)'D':
  206. if (!strcmp(pstrDisableDriver, pMethodName))
  207. lReturn = TRUE;
  208. else if (!strcmp(pstrDisablePDEV, pMethodName))
  209. lReturn = TRUE;
  210. #if 0
  211. else if (!strcmp(pstrDriverDMS, pMethodName))
  212. lReturn = TRUE;
  213. #endif
  214. #if 0
  215. else if (!strcmp(pstrDevMode, pMethodName))
  216. lReturn = TRUE;
  217. #endif
  218. #if 0
  219. else if (!strcmp(pstrDownloadFontHeader, pMethodName))
  220. lReturn = TRUE;
  221. #endif
  222. #if 0
  223. else if (!strcmp(pstrDownloadCharGlyph, pMethodName))
  224. lReturn = TRUE;
  225. #endif
  226. break;
  227. case (WCHAR)'E':
  228. if (!strcmp(pstrEnableDriver, pMethodName))
  229. lReturn = TRUE;
  230. else if (!strcmp(pstrEnablePDEV, pMethodName))
  231. lReturn = TRUE;
  232. break;
  233. case (WCHAR)'F':
  234. #if 0
  235. if (!strcmp(pstrFilterGraphics, pMethodName))
  236. lReturn = TRUE;
  237. #endif
  238. break;
  239. case (WCHAR)'G':
  240. if (!strcmp(pstrGetInfo, pMethodName))
  241. lReturn = TRUE;
  242. break;
  243. case (WCHAR)'H':
  244. #if 0
  245. if (!strcmp(pstrHalftonePattern, pMethodName))
  246. lReturn = TRUE;
  247. #endif
  248. break;
  249. case (WCHAR)'I':
  250. #if 0
  251. if (!strcmp(pstrImageProcessing, pMethodName))
  252. lReturn = TRUE;
  253. #endif
  254. break;
  255. case (WCHAR)'M':
  256. #if 0
  257. if (!strcmp(pstrMemoryUsage, pMethodName))
  258. lReturn = TRUE;
  259. #endif
  260. break;
  261. case (WCHAR)'O':
  262. if (!strcmp(pstrOutputCharStr, pMethodName))
  263. lReturn = TRUE;
  264. break;
  265. case (WCHAR)'R':
  266. #if 0
  267. if (!strcmp(pstrResetPDEV, pMethodName))
  268. lReturn = TRUE;
  269. #endif
  270. break;
  271. case (WCHAR)'S':
  272. if (!strcmp(pstrSendFontCmd, pMethodName))
  273. lReturn = TRUE;
  274. break;
  275. case (WCHAR)'T':
  276. if (!strcmp(pstrTTYGetInfo, pMethodName))
  277. lReturn = TRUE;
  278. #if 0
  279. else if (!strcmp(pstrTextOutAsBitmap, pMethodName))
  280. lReturn = TRUE;
  281. #endif
  282. #if 0
  283. else if (!strcmp(pstrTTDownloadMethod, pMethodName))
  284. lReturn = TRUE;
  285. #endif
  286. break;
  287. #if 0
  288. case (WCHAR)'W':
  289. if (!strcmp(pstrWritePrinter,pMethodName) )
  290. lReturn = TRUE;
  291. #endif
  292. break;
  293. }
  294. }
  295. if (lReturn)
  296. {
  297. VERBOSE(__TEXT("Supported\r\n"));
  298. return S_OK;
  299. }
  300. else
  301. {
  302. VERBOSE(__TEXT("NOT supported\r\n"));
  303. return S_FALSE;
  304. }
  305. }
  306. LONG __stdcall IOemCB::DevMode(
  307. DWORD dwMode,
  308. POEMDMPARAM pOemDMParam)
  309. {
  310. VERBOSE(DLLTEXT("IOemCB::DevMode() entry.\r\n"));
  311. return E_NOTIMPL;
  312. }
  313. LONG __stdcall IOemCB::CommandCallback(
  314. PDEVOBJ pdevobj,
  315. DWORD dwCallbackID,
  316. DWORD dwCount,
  317. PDWORD pdwParams,
  318. OUT INT *piResult)
  319. {
  320. VERBOSE(DLLTEXT("IOemCB::CommandCallback() entry.\r\n"));
  321. VERBOSE(DLLTEXT(" dwCallbackID = %d\r\n"), dwCallbackID);
  322. VERBOSE(DLLTEXT(" dwCount = %d\r\n"), dwCount);
  323. DWORD dwResult;
  324. PREGSTRUCT pMyStuff; // sebset of pGlobals
  325. PCMDSTR pSelectCmd = NULL ; // points to one of the command structures
  326. // in pMyStuff.
  327. *piResult = 0 ; // for all non movement commands
  328. pMyStuff = (PREGSTRUCT)pdevobj->pdevOEM ;
  329. switch(dwCallbackID)
  330. {
  331. case TTY_CB_BEGINJOB:
  332. pSelectCmd = &pMyStuff->BeginJob ;
  333. break;
  334. case TTY_CB_ENDJOB:
  335. pSelectCmd = &pMyStuff->EndJob ;
  336. break;
  337. case TTY_CB_PAPERSELECT:
  338. pSelectCmd = &pMyStuff->PaperSelect ;
  339. break;
  340. case TTY_CB_FEEDSELECT:
  341. pSelectCmd = &pMyStuff->FeedSelect ;
  342. break;
  343. case TTY_CB_BOLD_ON:
  344. pSelectCmd = &pMyStuff->Bold_ON ;
  345. break;
  346. case TTY_CB_BOLD_OFF:
  347. pSelectCmd = &pMyStuff->Bold_OFF ;
  348. break;
  349. case TTY_CB_UNDERLINE_ON:
  350. pSelectCmd = &pMyStuff->Underline_ON ;
  351. break;
  352. case TTY_CB_UNDERLINE_OFF:
  353. pSelectCmd = &pMyStuff->Underline_OFF ;
  354. break;
  355. default:
  356. return S_OK;
  357. }
  358. if(pSelectCmd)
  359. pOEMHelp->DrvWriteSpoolBuf(pdevobj, pSelectCmd->strCmd, pSelectCmd->dwLen,
  360. &dwResult);
  361. #if 0
  362. // this code is just to test new Unidrv helper functions.
  363. pOEMHelp->DrvWriteAbortBuf(pdevobj, pSelectCmd->strCmd, pSelectCmd->dwLen,
  364. 3000);
  365. // temp variables:
  366. DWORD dwcursorPosX, dwcursorPosY, cbNeeded ;
  367. PBYTE pBuffer;
  368. pOEMHelp->DrvGetStandardVariable( pdevobj,
  369. SVI_CURSORORIGINX,
  370. &dwcursorPosX,
  371. sizeof(DWORD),
  372. &cbNeeded);
  373. pOEMHelp->DrvGetStandardVariable( pdevobj,
  374. SVI_CURSORORIGINY,
  375. &dwcursorPosY,
  376. sizeof(DWORD),
  377. &cbNeeded);
  378. pOEMHelp->DrvGetGPDData( pdevobj,
  379. GPD_OEMCUSTOMDATA, // Type of the data
  380. NULL, // reserved. Should be set to 0
  381. NULL, // Caller allocated Buffer to be copied
  382. 0, // Size of the buffer
  383. &cbNeeded // New Size of the buffer if needed.
  384. ) ;
  385. pBuffer = (PBYTE)MemAlloc(cbNeeded);
  386. pOEMHelp->DrvGetGPDData( pdevobj,
  387. GPD_OEMCUSTOMDATA, // Type of the data
  388. NULL, // reserved. Should be set to 0
  389. pBuffer, // Caller allocated Buffer to be copied
  390. cbNeeded, // Size of the buffer
  391. &cbNeeded // New Size of the buffer if needed.
  392. ) ;
  393. pOEMHelp->DrvWriteSpoolBuf(pdevobj, pBuffer, cbNeeded,
  394. &dwResult);
  395. MemFree(pBuffer);
  396. #endif
  397. return S_OK;
  398. }
  399. LONG __stdcall IOemCB::ImageProcessing(
  400. PDEVOBJ pdevobj,
  401. PBYTE pSrcBitmap,
  402. PBITMAPINFOHEADER pBitmapInfoHeader,
  403. PBYTE pColorTable,
  404. DWORD dwCallbackID,
  405. PIPPARAMS pIPParams,
  406. OUT PBYTE *ppbResult)
  407. {
  408. VERBOSE(DLLTEXT("IOemCB::ImageProcessing() entry.\r\n"));
  409. return E_NOTIMPL ;
  410. /* if (*ppbResult = OEMImageProcessing(pdevobj, pSrcBitmap,
  411. pBitmapInfoHeader, pColorTable, dwCallbackID, pIPParams))
  412. return S_OK;
  413. else
  414. return E_FAIL; */
  415. }
  416. LONG __stdcall IOemCB::FilterGraphics(
  417. PDEVOBJ pdevobj,
  418. PBYTE pBuf,
  419. DWORD dwLen)
  420. {
  421. // DWORD dwResult;
  422. VERBOSE(DLLTEXT("IOemCB::FilterGraphis() entry.\r\n"));
  423. return E_NOTIMPL ;
  424. /* if (OEMFilterGraphics( pdevobj, pBuf, dwLen))
  425. return S_OK;
  426. else
  427. return E_FAIL; */
  428. }
  429. LONG __stdcall IOemCB::Compression(
  430. PDEVOBJ pdevobj,
  431. PBYTE pInBuf,
  432. PBYTE pOutBuf,
  433. DWORD dwInLen,
  434. DWORD dwOutLen,
  435. OUT INT *piResult)
  436. {
  437. VERBOSE(DLLTEXT("IOemCB::Compression() entry.\r\n"));
  438. return E_NOTIMPL;
  439. }
  440. LONG __stdcall IOemCB::HalftonePattern(
  441. PDEVOBJ pdevobj,
  442. PBYTE pHTPattern,
  443. DWORD dwHTPatternX,
  444. DWORD dwHTPatternY,
  445. DWORD dwHTNumPatterns,
  446. DWORD dwCallbackID,
  447. PBYTE pResource,
  448. DWORD dwResourceSize)
  449. {
  450. VERBOSE(DLLTEXT("IOemCB::HalftonePattern() entry.\r\n"));
  451. return E_NOTIMPL;
  452. }
  453. LONG __stdcall IOemCB::MemoryUsage(
  454. PDEVOBJ pdevobj,
  455. POEMMEMORYUSAGE pMemoryUsage)
  456. {
  457. VERBOSE(DLLTEXT("IOemCB::MemoryUsage() entry.\r\n"));
  458. return E_NOTIMPL;
  459. }
  460. LONG __stdcall IOemCB::DownloadFontHeader(
  461. PDEVOBJ pdevobj,
  462. PUNIFONTOBJ pUFObj,
  463. OUT DWORD *pdwResult)
  464. {
  465. VERBOSE(DLLTEXT("IOemCB::DownloadFontHeader() entry.\r\n"));
  466. return E_NOTIMPL;
  467. }
  468. LONG __stdcall IOemCB::DownloadCharGlyph(
  469. PDEVOBJ pdevobj,
  470. PUNIFONTOBJ pUFObj,
  471. HGLYPH hGlyph,
  472. PDWORD pdwWidth,
  473. OUT DWORD *pdwResult)
  474. {
  475. VERBOSE(DLLTEXT("IOemCB::DownloadCharGlyph() entry.\r\n"));
  476. return E_NOTIMPL;
  477. }
  478. LONG __stdcall IOemCB::TTDownloadMethod(
  479. PDEVOBJ pdevobj,
  480. PUNIFONTOBJ pUFObj,
  481. OUT DWORD *pdwResult)
  482. {
  483. VERBOSE(DLLTEXT("IOemCB::TTDownloadMethod() entry.\r\n"));
  484. return E_NOTIMPL;
  485. }
  486. LONG __stdcall IOemCB::OutputCharStr(
  487. PDEVOBJ pdevobj,
  488. PUNIFONTOBJ pUFObj,
  489. DWORD dwType,
  490. DWORD dwCount,
  491. PVOID pGlyph)
  492. {
  493. GETINFO_GLYPHSTRING GStr;
  494. PTRANSDATA pTrans;
  495. DWORD dwI, dwGetInfo, dwResult, dwGlyphBufSiz, dwSpoolBufSiz, dwDst;
  496. PREGSTRUCT pMyStuff;
  497. VERBOSE(DLLTEXT("OEMOutputCharStr() entry.\r\n"));
  498. pMyStuff = (PREGSTRUCT)pdevobj->pdevOEM ;
  499. // is the glyph buffers cache large enough?
  500. dwGlyphBufSiz = dwCount * sizeof(TRANSDATA);
  501. if(dwGlyphBufSiz > pMyStuff->dwGlyphBufSiz) // need to realloc mem.
  502. {
  503. if(pMyStuff->aubGlyphBuf)
  504. {
  505. MemFree(pMyStuff->aubGlyphBuf) ;
  506. pMyStuff->dwGlyphBufSiz = 0 ;
  507. }
  508. if(pMyStuff->aubGlyphBuf = (PBYTE)MemAlloc(dwGlyphBufSiz))
  509. pMyStuff->dwGlyphBufSiz = dwGlyphBufSiz ;
  510. else
  511. return(E_FAIL); // unable to alloc needed buffers.
  512. }
  513. dwSpoolBufSiz = dwCount * sizeof(WORD); // assume worst case.
  514. if(dwSpoolBufSiz > pMyStuff->dwSpoolBufSiz) // need to realloc mem.
  515. {
  516. if(pMyStuff->aubSpoolBuf)
  517. {
  518. MemFree(pMyStuff->aubSpoolBuf) ;
  519. pMyStuff->dwSpoolBufSiz = 0 ;
  520. }
  521. if(pMyStuff->aubSpoolBuf = (PBYTE)MemAlloc(dwSpoolBufSiz))
  522. pMyStuff->dwSpoolBufSiz = dwSpoolBufSiz ;
  523. else
  524. return(E_FAIL); // unable to alloc needed buffers.
  525. }
  526. if(dwType != TYPE_GLYPHHANDLE)
  527. return(E_FAIL); // E_FAIL can only handle device fonts.
  528. GStr.dwSize = sizeof(GETINFO_GLYPHSTRING);
  529. GStr.dwCount = dwCount;
  530. GStr.dwTypeIn = dwType;
  531. GStr.pGlyphIn = pGlyph;
  532. GStr.dwTypeOut = TYPE_TRANSDATA;
  533. GStr.pGlyphOut = pMyStuff->aubGlyphBuf ;
  534. GStr.dwGlyphOutSize = dwGlyphBufSiz; // instead of pMyStuff->dwGlyphBufSiz, which cause AV
  535. dwGetInfo = GStr.dwSize;
  536. if (!pUFObj->pfnGetInfo(pUFObj, UFO_GETINFO_GLYPHSTRING, &GStr,
  537. dwGetInfo, &dwGetInfo))
  538. {
  539. WARNING(DLLTEXT("UNIFONTOBJ_GetInfo:UFO_GETINFO_GLYPHSTRING failed.\r\n"));
  540. return(E_FAIL);
  541. }
  542. pTrans = (PTRANSDATA)pMyStuff->aubGlyphBuf;
  543. for (dwDst = dwI = 0 ; dwI < dwCount; dwI++, pTrans++)
  544. {
  545. VERBOSE(DLLTEXT("TYPE_TRANSDATA:ubCodePageID:0x%x\n"),pTrans->ubCodePageID);
  546. VERBOSE(DLLTEXT("TYPE_TRANSDATA:ubType:0x%x\n"),pTrans->ubType);
  547. switch (pTrans->ubType & MTYPE_FORMAT_MASK)
  548. {
  549. case MTYPE_DIRECT:
  550. pMyStuff->aubSpoolBuf[dwDst++] = pTrans->uCode.ubCode ;
  551. break;
  552. case MTYPE_PAIRED:
  553. VERBOSE(DLLTEXT("TYPE_TRANSDATA:ubPairs:0x%x\n"),*(PWORD)(pTrans->uCode.ubPairs));
  554. pMyStuff->aubSpoolBuf[dwDst++] = pTrans->uCode.ubPairs[0] ;
  555. pMyStuff->aubSpoolBuf[dwDst++] = pTrans->uCode.ubPairs[1] ;
  556. break;
  557. default:
  558. return (E_FAIL); // no other MTYPE is supported.
  559. break;
  560. }
  561. }
  562. // send dst bytes to printer.
  563. pOEMHelp->DrvWriteSpoolBuf(pdevobj, pMyStuff->aubSpoolBuf, dwDst,
  564. &dwResult);
  565. if(dwResult == dwDst)
  566. return S_OK;
  567. return E_FAIL ;
  568. }
  569. LONG __stdcall IOemCB::SendFontCmd(
  570. PDEVOBJ pdevobj,
  571. PUNIFONTOBJ pUFObj,
  572. PFINVOCATION pFInv)
  573. {
  574. VERBOSE(DLLTEXT("IOemCB::SendFontCmd() entry.\r\n"));
  575. PREGSTRUCT pMyStuff; // sebset of pGlobals
  576. PCMDSTR pSelectCmd ; // points to one of the font selection
  577. // command structures in pMyStuff.
  578. DWORD dwResult;
  579. // I expect pFInv to contain either "10", "12" or "17"
  580. pMyStuff = (PREGSTRUCT)pdevobj->pdevOEM ;
  581. if(pFInv->dwCount == 2 && pFInv->pubCommand[0] == '1')
  582. {
  583. if (pFInv->pubCommand[1] == '2')
  584. pSelectCmd = &pMyStuff->Sel_12_cpi ;
  585. else if (pFInv->pubCommand[1] == '7')
  586. pSelectCmd = &pMyStuff->Sel_17_cpi ;
  587. else if (pFInv->pubCommand[1] == '0')
  588. pSelectCmd = &pMyStuff->Sel_10_cpi ;
  589. else
  590. return S_OK; // maybe asking to deselect a font. Don't do anything!
  591. }
  592. else
  593. return S_OK; // maybe asking to deselect a font. Don't do anything!
  594. pOEMHelp->DrvWriteSpoolBuf(pdevobj, pSelectCmd->strCmd, pSelectCmd->dwLen,
  595. &dwResult);
  596. return S_OK;
  597. }
  598. LONG __stdcall IOemCB::DriverDMS(
  599. PVOID pDevObj,
  600. PVOID pBuffer,
  601. DWORD cbSize,
  602. PDWORD pcbNeeded)
  603. {
  604. VERBOSE(DLLTEXT("IOemCB::DriverDMS() entry.\r\n"));
  605. return E_NOTIMPL;
  606. }
  607. LONG __stdcall IOemCB::TextOutAsBitmap(
  608. SURFOBJ *pso,
  609. STROBJ *pstro,
  610. FONTOBJ *pfo,
  611. CLIPOBJ *pco,
  612. RECTL *prclExtra,
  613. RECTL *prclOpaque,
  614. BRUSHOBJ *pboFore,
  615. BRUSHOBJ *pboOpaque,
  616. POINTL *pptlOrg,
  617. MIX mix)
  618. {
  619. VERBOSE(DLLTEXT("IOemCB::TextOutAsBitmap() entry.\r\n"));
  620. return E_NOTIMPL;
  621. }
  622. LONG __stdcall IOemCB::TTYGetInfo(
  623. PDEVOBJ pdevobj,
  624. DWORD dwInfoIndex,
  625. PVOID pOutputBuf,
  626. DWORD dwSize,
  627. DWORD *pcbcNeeded
  628. )
  629. {
  630. VERBOSE(DLLTEXT("IOemCB::TTYGetInfo() entry.\r\n"));
  631. if(OEMTTYGetInfo( pdevobj, dwInfoIndex,
  632. pOutputBuf, dwSize, pcbcNeeded) )
  633. return S_OK;
  634. return E_FAIL ;
  635. }
  636. LONG __stdcall IOemCB:: WritePrinter ( PDEVOBJ pdevobj,
  637. PVOID pBuf,
  638. DWORD cbBuffer,
  639. PDWORD pcbWritten)
  640. {
  641. VERBOSE(DLLTEXT("IOemCB::WritePrinter() entry.\r\n"));
  642. return E_NOTIMPL;
  643. }
  644. ////////////////////////////////////////////////////////////////////////////////
  645. //
  646. // oem class factory
  647. //
  648. class IOemCF : public IClassFactory
  649. {
  650. public:
  651. // *** IUnknown methods ***
  652. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj);
  653. STDMETHOD_(ULONG,AddRef) (THIS);
  654. STDMETHOD_(ULONG,Release) (THIS);
  655. // *** IClassFactory methods ***
  656. STDMETHOD(CreateInstance) (THIS_
  657. LPUNKNOWN pUnkOuter,
  658. REFIID riid,
  659. LPVOID FAR* ppvObject);
  660. STDMETHOD(LockServer) (THIS_ BOOL bLock);
  661. // Constructor
  662. IOemCF(): m_cRef(1) { };
  663. ~IOemCF() { };
  664. protected:
  665. LONG m_cRef;
  666. };
  667. ///////////////////////////////////////////////////////////
  668. //
  669. // Class factory body
  670. //
  671. HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv)
  672. {
  673. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  674. {
  675. *ppv = static_cast<IOemCF*>(this) ;
  676. }
  677. else
  678. {
  679. *ppv = NULL ;
  680. return E_NOINTERFACE ;
  681. }
  682. reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
  683. return S_OK ;
  684. }
  685. ULONG __stdcall IOemCF::AddRef()
  686. {
  687. return InterlockedIncrement(&m_cRef) ;
  688. }
  689. ULONG __stdcall IOemCF::Release()
  690. {
  691. ASSERT( 0 != m_cRef);
  692. ULONG cRef = InterlockedDecrement(&m_cRef);
  693. if (0 == cRef)
  694. {
  695. delete this;
  696. }
  697. return cRef;
  698. }
  699. // IClassFactory implementation
  700. HRESULT __stdcall IOemCF::CreateInstance(IUnknown* pUnknownOuter,
  701. const IID& iid,
  702. void** ppv)
  703. {
  704. VERBOSE(DLLTEXT("Class factory:\t\tCreate component.")) ;
  705. // Cannot aggregate.
  706. if (pUnknownOuter != NULL)
  707. {
  708. return CLASS_E_NOAGGREGATION ;
  709. }
  710. // Create component.
  711. IOemCB* pOemCB = new IOemCB ;
  712. if (pOemCB == NULL)
  713. {
  714. return E_OUTOFMEMORY ;
  715. }
  716. // Get the requested interface.
  717. HRESULT hr = pOemCB->QueryInterface(iid, ppv) ;
  718. // Release the IUnknown pointer.
  719. // (If QueryInterface failed, component will delete itself.)
  720. pOemCB->Release() ;
  721. return hr ;
  722. }
  723. // LockServer
  724. HRESULT __stdcall IOemCF::LockServer(BOOL bLock)
  725. {
  726. if (bLock)
  727. {
  728. InterlockedIncrement(&g_cServerLocks) ;
  729. }
  730. else
  731. {
  732. InterlockedDecrement(&g_cServerLocks) ;
  733. }
  734. return S_OK ;
  735. }
  736. ///////////////////////////////////////////////////////////
  737. //
  738. // Registration functions
  739. // Testing purpose
  740. //
  741. //
  742. // Can DLL unload now?
  743. //
  744. STDAPI DllCanUnloadNow()
  745. {
  746. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  747. {
  748. return S_OK ;
  749. }
  750. else
  751. {
  752. return S_FALSE ;
  753. }
  754. }
  755. //
  756. // Get class factory
  757. //
  758. STDAPI DllGetClassObject(const CLSID& clsid,
  759. const IID& iid,
  760. void** ppv)
  761. {
  762. VERBOSE(DLLTEXT("DllGetClassObject:\tCreate class factory.")) ;
  763. // Can we create this component?
  764. if (clsid != CLSID_OEMRENDER)
  765. {
  766. return CLASS_E_CLASSNOTAVAILABLE ;
  767. }
  768. // Create class factory.
  769. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  770. // in constructor
  771. if (pFontCF == NULL)
  772. {
  773. return E_OUTOFMEMORY ;
  774. }
  775. // Get requested interface.
  776. HRESULT hr = pFontCF->QueryInterface(iid, ppv) ;
  777. pFontCF->Release() ;
  778. return hr ;
  779. }
  780. ///////////////////////////////////////////////////////////
  781. //
  782. // DLL module information
  783. //
  784. BOOL APIENTRY DllMain(HANDLE hModule,
  785. DWORD dwReason,
  786. void* lpReserved)
  787. {
  788. if (dwReason == DLL_PROCESS_ATTACH)
  789. {
  790. g_hModule = (HMODULE)hModule ;
  791. }
  792. g_hModule = (HMODULE)hModule ;
  793. return SUCCEEDED(S_OK);
  794. }