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.

614 lines
12 KiB

  1. /*++
  2. Copyright (c) 1996-1998 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 long g_cComponents = 0 ; // Count of active components
  18. static long g_cServerLocks = 0 ; // Count of locks
  19. ////////////////////////////////////////////////////////////////////////////////
  20. //
  21. // Interface Oem CallBack definition
  22. //
  23. class IOemCB : public IPrintOemUni
  24. {
  25. public:
  26. //
  27. // IUnknown methods
  28. //
  29. STDMETHODIMP
  30. QueryInterface(
  31. REFIID riid,
  32. PVOID *ppv)
  33. {
  34. if (NULL == ppv)
  35. return E_NOINTERFACE;
  36. if (riid == IID_IUnknown)
  37. {
  38. *ppv = static_cast<IUnknown *>(this);
  39. }
  40. else if (riid == IID_IPrintOemUni)
  41. {
  42. *ppv = static_cast<IPrintOemUni *>(this);
  43. }
  44. else
  45. {
  46. *ppv = NULL;
  47. return E_NOINTERFACE;
  48. }
  49. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  50. return S_OK;
  51. }
  52. STDMETHODIMP_(ULONG)
  53. AddRef()
  54. {
  55. return InterlockedIncrement(&m_cRef);
  56. }
  57. STDMETHODIMP_(ULONG)
  58. Release()
  59. {
  60. if (0 == InterlockedDecrement(&m_cRef))
  61. {
  62. delete this ;
  63. return 0;
  64. }
  65. return m_cRef ;
  66. }
  67. //
  68. // IPrintOemCommon methods
  69. //
  70. STDMETHODIMP
  71. DevMode(
  72. DWORD dwMode,
  73. POEMDMPARAM pOemDMParam)
  74. {
  75. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\r\n")));
  76. if (OEMDevMode(dwMode, pOemDMParam))
  77. return S_OK;
  78. else
  79. return E_FAIL;
  80. }
  81. STDMETHODIMP
  82. GetInfo(
  83. DWORD dwMode,
  84. PVOID pBuffer,
  85. DWORD cbSize,
  86. PDWORD pcbNeeded)
  87. {
  88. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\r\n")));
  89. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  90. return S_OK;
  91. else
  92. return E_FAIL;
  93. }
  94. //
  95. // IPrintOemEngine methods
  96. //
  97. STDMETHODIMP
  98. EnableDriver(
  99. DWORD dwDriverVersion,
  100. DWORD cbSize,
  101. PDRVENABLEDATA pded)
  102. {
  103. VERBOSE((DLLTEXT("IOemCB::EnableDriver() entry.\r\n")));
  104. return S_OK;
  105. }
  106. STDMETHODIMP
  107. DisableDriver()
  108. {
  109. VERBOSE((DLLTEXT("IOemCB::DisaleDriver() entry.\r\n")));
  110. if (this->pOEMHelp)
  111. {
  112. this->pOEMHelp->Release();
  113. this->pOEMHelp = NULL;
  114. }
  115. return S_OK;
  116. }
  117. STDMETHODIMP
  118. EnablePDEV(
  119. PDEVOBJ pdevobj,
  120. PWSTR pPrinterName,
  121. ULONG cPatterns,
  122. HSURF *phsurfPatterns,
  123. ULONG cjGdiInfo,
  124. GDIINFO *pGdiInfo,
  125. ULONG cjDevInfo,
  126. DEVINFO *pDevInfo,
  127. DRVENABLEDATA *pded,
  128. PDEVOEM *pDevOem)
  129. {
  130. PDEVOEM pTemp;
  131. pTemp = OEMEnablePDEV(pdevobj,
  132. pPrinterName, cPatterns, phsurfPatterns,
  133. cjGdiInfo, pGdiInfo, cjDevInfo, pDevInfo, pded);
  134. if (NULL == pTemp) {
  135. return E_FAIL;
  136. }
  137. //
  138. // Save necessary helpder function addresses.
  139. //
  140. ((MINIDEV *)pTemp)->pIntf = this->pOEMHelp;
  141. *pDevOem = pTemp;
  142. return S_OK;
  143. }
  144. STDMETHODIMP
  145. DisablePDEV(
  146. PDEVOBJ pdevobj)
  147. {
  148. VERBOSE(((DLLTEXT("IOemCB::DisablePDEV() entry.\n"))));
  149. OEMDisablePDEV(pdevobj);
  150. return S_OK;
  151. }
  152. STDMETHODIMP
  153. ResetPDEV(
  154. PDEVOBJ pdevobjOld,
  155. PDEVOBJ pdevobjNew)
  156. {
  157. if (OEMResetPDEV(pdevobjOld, pdevobjNew))
  158. return S_OK;
  159. else
  160. return E_FAIL;
  161. }
  162. //
  163. // IPrintOemUni methods
  164. //
  165. STDMETHODIMP
  166. PublishDriverInterface(
  167. IUnknown *pIUnknown)
  168. {
  169. VERBOSE((DLLTEXT("IOemCB::PublishDriverInterface() entry.\r\n")));
  170. if (this->pOEMHelp == NULL)
  171. {
  172. HRESULT hResult;
  173. // Get Interface to Helper Functions.
  174. hResult = pIUnknown->QueryInterface(
  175. IID_IPrintOemDriverUni,
  176. (void** )&(this->pOEMHelp));
  177. if(!SUCCEEDED(hResult))
  178. {
  179. this->pOEMHelp = NULL;
  180. return E_FAIL;
  181. }
  182. }
  183. return S_OK;
  184. }
  185. static
  186. int __cdecl
  187. iCompNames(
  188. const void *p1,
  189. const void *p2) {
  190. return strcmp(
  191. (NULL == p1 ? "" : *((char **)p1)),
  192. (NULL == p2 ? "" : *((char **)p2)));
  193. }
  194. STDMETHODIMP
  195. GetImplementedMethod(
  196. PSTR pMethodName)
  197. {
  198. LONG lRet = E_FAIL;
  199. if (SUCCEEDED(StringCchLengthA(
  200. pMethodName, MAX_METHODNAME, NULL))) {
  201. PSTR pTemp;
  202. pTemp = (PSTR)bsearch(
  203. &pMethodName,
  204. gMethodsSupported,
  205. (sizeof (gMethodsSupported) / sizeof (PSTR)),
  206. sizeof (PSTR),
  207. iCompNames);
  208. if (NULL != pTemp)
  209. lRet = S_OK;
  210. }
  211. VERBOSE(("GetImplementedMethod: %s - %d\n",
  212. pMethodName, lRet));
  213. return lRet;
  214. }
  215. STDMETHODIMP
  216. DriverDMS(
  217. PVOID pDevObj,
  218. PVOID pBuffer,
  219. DWORD cbSize,
  220. PDWORD pcbNeeded)
  221. {
  222. return E_NOTIMPL;
  223. }
  224. STDMETHODIMP
  225. CommandCallback(
  226. PDEVOBJ pdevobj,
  227. DWORD dwCallbackID,
  228. DWORD dwCount,
  229. PDWORD pdwParams,
  230. OUT INT *piResult)
  231. {
  232. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\r\n")));
  233. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  234. return S_OK;
  235. }
  236. STDMETHODIMP
  237. ImageProcessing(
  238. PDEVOBJ pdevobj,
  239. PBYTE pSrcBitmap,
  240. PBITMAPINFOHEADER pBitmapInfoHeader,
  241. PBYTE pColorTable,
  242. DWORD dwCallbackID,
  243. PIPPARAMS pIPParams,
  244. PBYTE *ppbResult)
  245. {
  246. return E_NOTIMPL;
  247. }
  248. STDMETHODIMP
  249. FilterGraphics(
  250. PDEVOBJ pdevobj,
  251. PBYTE pBuf,
  252. DWORD dwLen)
  253. {
  254. return E_NOTIMPL;
  255. }
  256. STDMETHODIMP
  257. Compression(
  258. PDEVOBJ pdevobj,
  259. PBYTE pInBuf,
  260. PBYTE pOutBuf,
  261. DWORD dwInLen,
  262. DWORD dwOutLen,
  263. INT *piResult)
  264. {
  265. return E_NOTIMPL;
  266. }
  267. STDMETHODIMP
  268. HalftonePattern(
  269. PDEVOBJ pdevobj,
  270. PBYTE pHTPattern,
  271. DWORD dwHTPatternX,
  272. DWORD dwHTPatternY,
  273. DWORD dwHTNumPatterns,
  274. DWORD dwCallbackID,
  275. PBYTE pResource,
  276. DWORD dwResourceSize)
  277. {
  278. return E_NOTIMPL;
  279. }
  280. STDMETHODIMP
  281. MemoryUsage(
  282. PDEVOBJ pdevobj,
  283. POEMMEMORYUSAGE pMemoryUsage)
  284. {
  285. return E_NOTIMPL;
  286. }
  287. STDMETHODIMP
  288. TTYGetInfo(
  289. PDEVOBJ pdevobj,
  290. DWORD dwInfoIndex,
  291. PVOID pOutputBuf,
  292. DWORD dwSize,
  293. DWORD *pcbcNeeded)
  294. {
  295. return E_NOTIMPL;
  296. }
  297. STDMETHODIMP
  298. DownloadFontHeader(
  299. PDEVOBJ pdevobj,
  300. PUNIFONTOBJ pUFObj,
  301. DWORD *pdwResult)
  302. {
  303. return E_NOTIMPL;
  304. }
  305. STDMETHODIMP
  306. DownloadCharGlyph(
  307. PDEVOBJ pdevobj,
  308. PUNIFONTOBJ pUFObj,
  309. HGLYPH hGlyph,
  310. PDWORD pdwWidth,
  311. DWORD *pdwResult)
  312. {
  313. return E_NOTIMPL;
  314. }
  315. STDMETHODIMP
  316. TTDownloadMethod(
  317. PDEVOBJ pdevobj,
  318. PUNIFONTOBJ pUFObj,
  319. DWORD *pdwResult)
  320. {
  321. return E_NOTIMPL;
  322. }
  323. STDMETHODIMP
  324. OutputCharStr(
  325. PDEVOBJ pdevobj,
  326. PUNIFONTOBJ pUFObj,
  327. DWORD dwType,
  328. DWORD dwCount,
  329. PVOID pGlyph)
  330. {
  331. VERBOSE(("OutputCharStr\n"));
  332. if( myOEMOutputCharStr(pdevobj,pUFObj, dwType, dwCount, pGlyph) )
  333. return S_OK;
  334. else
  335. return E_FAIL;
  336. }
  337. STDMETHODIMP
  338. SendFontCmd(
  339. PDEVOBJ pdevobj,
  340. PUNIFONTOBJ pUFObj,
  341. PFINVOCATION pFInv)
  342. {
  343. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\r\n")));
  344. OEMSendFontCmd(pdevobj, pUFObj, pFInv);
  345. return S_OK;
  346. }
  347. STDMETHODIMP
  348. TextOutAsBitmap(
  349. SURFOBJ *pso,
  350. STROBJ *pstro,
  351. FONTOBJ *pfo,
  352. CLIPOBJ *pco,
  353. RECTL *prclExtra,
  354. RECTL *prclOpaque,
  355. BRUSHOBJ *pboFore,
  356. BRUSHOBJ *pboOpaque,
  357. POINTL *pptlOrg,
  358. MIX mix)
  359. {
  360. return E_NOTIMPL;
  361. }
  362. //
  363. // Constructors
  364. //
  365. IOemCB() { m_cRef = 1; pOEMHelp = NULL; };
  366. ~IOemCB() { };
  367. protected:
  368. IPrintOemDriverUni* pOEMHelp;
  369. LONG m_cRef;
  370. };
  371. //
  372. // Make the Unidrv helper functions (defined in C++)
  373. // accesible to C.
  374. //
  375. extern "C" {
  376. //
  377. // DrvWriteSpoolBuf()
  378. //
  379. HRESULT
  380. XXXDrvWriteSpoolBuf(
  381. VOID *pIntf,
  382. PDEVOBJ pdevobj,
  383. PVOID pBuffer,
  384. DWORD cbSize,
  385. DWORD *pdwResult) {
  386. return ((IPrintOemDriverUni *)pIntf)->DrvWriteSpoolBuf(
  387. pdevobj,
  388. pBuffer,
  389. cbSize,
  390. pdwResult);
  391. }
  392. }
  393. class IOemCF : public IClassFactory
  394. {
  395. public:
  396. //
  397. // IUnknown methods
  398. //
  399. STDMETHODIMP
  400. QueryInterface(
  401. REFIID riid,
  402. PVOID *ppv)
  403. {
  404. if (NULL == ppv)
  405. return E_NOINTERFACE;
  406. if ((riid == IID_IUnknown) || (riid == IID_IClassFactory))
  407. {
  408. *ppv = static_cast<IOemCF*>(this);
  409. }
  410. else
  411. {
  412. *ppv = NULL ;
  413. return E_NOINTERFACE ;
  414. }
  415. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  416. return S_OK;
  417. }
  418. STDMETHODIMP_(ULONG)
  419. AddRef()
  420. {
  421. return InterlockedIncrement(&m_cRef);
  422. }
  423. STDMETHODIMP_(ULONG)
  424. Release()
  425. {
  426. if (0 == InterlockedDecrement(&m_cRef))
  427. {
  428. delete this;
  429. return 0;
  430. }
  431. return m_cRef;
  432. }
  433. STDMETHODIMP
  434. CreateInstance(
  435. LPUNKNOWN pUnknownOuter,
  436. const IID& iid,
  437. void **ppv)
  438. {
  439. // Cannot aggregate.
  440. if (pUnknownOuter != NULL)
  441. {
  442. return CLASS_E_NOAGGREGATION;
  443. }
  444. // Create component.
  445. IOemCB* pOemCB = new IOemCB;
  446. if (pOemCB == NULL)
  447. {
  448. return E_OUTOFMEMORY;
  449. }
  450. // Get the requested interface.
  451. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  452. // Release the IUnknown pointer.
  453. // (If QueryInterface failed, component will delete itself.)
  454. pOemCB->Release();
  455. return hr;
  456. }
  457. STDMETHODIMP
  458. LockServer(
  459. BOOL bLock)
  460. {
  461. if (bLock)
  462. {
  463. InterlockedIncrement(&g_cServerLocks);
  464. }
  465. else
  466. {
  467. InterlockedDecrement(&g_cServerLocks);
  468. }
  469. return S_OK ;
  470. }
  471. //
  472. // Constructors
  473. //
  474. IOemCF(): m_cRef(1) { };
  475. ~IOemCF() { };
  476. protected:
  477. LONG m_cRef;
  478. };
  479. ///////////////////////////////////////////////////////////
  480. //
  481. // Export functions
  482. //
  483. STDAPI
  484. DllCanUnloadNow(
  485. VOID)
  486. {
  487. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  488. {
  489. return S_OK ;
  490. }
  491. else
  492. {
  493. return S_FALSE ;
  494. }
  495. }
  496. STDAPI
  497. DllGetClassObject(
  498. const CLSID& clsid,
  499. const IID& iid,
  500. void** ppv)
  501. {
  502. // Can we create this component?
  503. if (clsid != CLSID_OEMRENDER)
  504. {
  505. return CLASS_E_CLASSNOTAVAILABLE ;
  506. }
  507. // Create class factory.
  508. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  509. // in constructor
  510. if (pFontCF == NULL)
  511. {
  512. return E_OUTOFMEMORY ;
  513. }
  514. // Get requested interface.
  515. HRESULT hr = pFontCF->QueryInterface(iid, ppv) ;
  516. pFontCF->Release() ;
  517. return hr ;
  518. }