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.

578 lines
13 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. #include "pdev.h"
  14. #include "name.h"
  15. #include <initguid.h>
  16. #include <prcomoem.h>
  17. #include <strsafe.h>
  18. // Globals
  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. 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. LONG __stdcall IOemCB::EnableDriver(DWORD dwDriverVersion,
  68. DWORD cbSize,
  69. PDRVENABLEDATA pded)
  70. {
  71. VERBOSE((DLLTEXT("IOemCB::EnableDriver() entry.\n")));
  72. // OEMEnableDriver(dwDriverVersion, cbSize, pded);
  73. // Need to return S_OK so that DisableDriver will be
  74. // called for cleanup.
  75. return S_OK;
  76. }
  77. LONG __stdcall IOemCB::DisableDriver(VOID)
  78. {
  79. VERBOSE((DLLTEXT("IOemCB::DisaleDriver() entry.\n")));
  80. // Release reference to Printer Driver's interface.
  81. if (this->pOEMHelp)
  82. {
  83. this->pOEMHelp->Release();
  84. this->pOEMHelp = NULL;
  85. }
  86. return S_OK;
  87. }
  88. LONG __stdcall IOemCB::PublishDriverInterface(
  89. IUnknown *pIUnknown)
  90. {
  91. VERBOSE((DLLTEXT("IOemCB::PublishDriverInterface() entry.\n")));
  92. if (NULL == pIUnknown)
  93. {
  94. return E_FAIL;
  95. }
  96. // Sep.8.98 ->
  97. // Need to store pointer to Driver Helper functions, if we already haven't.
  98. if (this->pOEMHelp == NULL)
  99. {
  100. HRESULT hResult;
  101. // Get Interface to Helper Functions.
  102. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUni, (void** )&(this->pOEMHelp));
  103. if(!SUCCEEDED(hResult))
  104. {
  105. // Make sure that interface pointer reflects interface query failure.
  106. this->pOEMHelp = NULL;
  107. return E_FAIL;
  108. }
  109. }
  110. // Sep.8.98 <-
  111. return S_OK;
  112. }
  113. LONG __stdcall IOemCB::EnablePDEV(
  114. PDEVOBJ pdevobj,
  115. PWSTR pPrinterName,
  116. ULONG cPatterns,
  117. HSURF *phsurfPatterns,
  118. ULONG cjGdiInfo,
  119. GDIINFO *pGdiInfo,
  120. ULONG cjDevInfo,
  121. DEVINFO *pDevInfo,
  122. DRVENABLEDATA *pded,
  123. OUT PDEVOEM *pDevOem)
  124. {
  125. VERBOSE((DLLTEXT("IOemCB::EnablePDEV() entry.\n")));
  126. if (NULL == pDevOem)
  127. {
  128. return E_FAIL;
  129. }
  130. *pDevOem = OEMEnablePDEV(pdevobj, pPrinterName, cPatterns, phsurfPatterns,
  131. cjGdiInfo, pGdiInfo, cjDevInfo, pDevInfo, pded);
  132. if (*pDevOem)
  133. return S_OK;
  134. else
  135. return E_FAIL;
  136. }
  137. LONG __stdcall IOemCB::ResetPDEV(
  138. PDEVOBJ pdevobjOld,
  139. PDEVOBJ pdevobjNew)
  140. {
  141. if (OEMResetPDEV(pdevobjOld, pdevobjNew))
  142. return S_OK;
  143. else
  144. return E_FAIL;
  145. }
  146. LONG __stdcall IOemCB::DisablePDEV(
  147. PDEVOBJ pdevobj)
  148. {
  149. VERBOSE((DLLTEXT("IOemCB::DisablePDEV() entry.\n")));
  150. OEMDisablePDEV(pdevobj);
  151. return S_OK;
  152. }
  153. LONG __stdcall IOemCB::GetInfo (
  154. DWORD dwMode,
  155. PVOID pBuffer,
  156. DWORD cbSize,
  157. PDWORD pcbNeeded)
  158. {
  159. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  160. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  161. return S_OK;
  162. else
  163. return E_FAIL;
  164. }
  165. LONG __stdcall IOemCB::GetImplementedMethod(
  166. PSTR pMethodName)
  167. {
  168. BOOL bReturn;
  169. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  170. VERBOSE((DLLTEXT(" Function:%s:"), pMethodName));
  171. bReturn = FALSE;
  172. if (!SUCCEEDED(StringCchLengthA(
  173. pMethodName, MAX_METHODNAME, NULL)))
  174. {
  175. VERBOSE(("Not supported (1)\n"));
  176. return E_NOTIMPL;
  177. }
  178. switch (*pMethodName)
  179. {
  180. case (WCHAR)'C':
  181. if (!strcmp(pstrCommandCallback, pMethodName))
  182. bReturn = TRUE;
  183. break;
  184. case (WCHAR)'D':
  185. if (!strcmp(pstrDisablePDEV, pMethodName))
  186. bReturn = TRUE;
  187. if (!strcmp(pstrDevMode, pMethodName))
  188. bReturn = TRUE;
  189. break;
  190. case (WCHAR)'E':
  191. if (!strcmp(pstrEnablePDEV, pMethodName))
  192. bReturn = TRUE;
  193. break;
  194. case (WCHAR)'F':
  195. if (!strcmp(pstrFilterGraphics, pMethodName))
  196. bReturn = TRUE;
  197. break;
  198. case (WCHAR)'G':
  199. if (!strcmp(pstrGetInfo, pMethodName))
  200. bReturn = TRUE;
  201. break;
  202. }
  203. if (bReturn)
  204. {
  205. VERBOSE(("Supported\n"));
  206. return S_OK;
  207. }
  208. else
  209. {
  210. VERBOSE(("Not supported (2)\n"));
  211. return E_NOTIMPL;
  212. }
  213. }
  214. LONG __stdcall IOemCB::DevMode(
  215. DWORD dwMode,
  216. POEMDMPARAM pOemDMParam)
  217. {
  218. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  219. return E_NOTIMPL;
  220. }
  221. LONG __stdcall IOemCB::CommandCallback(
  222. PDEVOBJ pdevobj,
  223. DWORD dwCallbackID,
  224. DWORD dwCount,
  225. PDWORD pdwParams,
  226. OUT INT *piResult)
  227. {
  228. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\n")));
  229. if (NULL == piResult)
  230. return E_FAIL;
  231. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  232. // #94193: shold create temp. file on spooler directory.
  233. if (*piResult < 0)
  234. return E_FAIL;
  235. return S_OK;
  236. }
  237. LONG __stdcall IOemCB::ImageProcessing(
  238. PDEVOBJ pdevobj,
  239. PBYTE pSrcBitmap,
  240. PBITMAPINFOHEADER pBitmapInfoHeader,
  241. PBYTE pColorTable,
  242. DWORD dwCallbackID,
  243. PIPPARAMS pIPParams,
  244. OUT PBYTE *ppbResult)
  245. {
  246. VERBOSE((DLLTEXT("IOemCB::ImageProcessing() entry.\n")));
  247. return E_NOTIMPL;
  248. }
  249. LONG __stdcall IOemCB::FilterGraphics(
  250. PDEVOBJ pdevobj,
  251. PBYTE pBuf,
  252. DWORD dwLen)
  253. {
  254. VERBOSE((DLLTEXT("IOemCB::FilterGraphis() entry.\n")));
  255. if(OEMFilterGraphics(pdevobj, pBuf, dwLen))
  256. return S_OK;
  257. else
  258. return E_FAIL;
  259. }
  260. LONG __stdcall IOemCB::Compression(
  261. PDEVOBJ pdevobj,
  262. PBYTE pInBuf,
  263. PBYTE pOutBuf,
  264. DWORD dwInLen,
  265. DWORD dwOutLen,
  266. OUT INT *piResult)
  267. {
  268. VERBOSE((DLLTEXT("IOemCB::Compression() entry.\n")));
  269. return E_NOTIMPL;
  270. }
  271. LONG __stdcall IOemCB::HalftonePattern(
  272. PDEVOBJ pdevobj,
  273. PBYTE pHTPattern,
  274. DWORD dwHTPatternX,
  275. DWORD dwHTPatternY,
  276. DWORD dwHTNumPatterns,
  277. DWORD dwCallbackID,
  278. PBYTE pResource,
  279. DWORD dwResourceSize)
  280. {
  281. VERBOSE((DLLTEXT("IOemCB::HalftonePattern() entry.\n")));
  282. return E_NOTIMPL;
  283. }
  284. LONG __stdcall IOemCB::MemoryUsage(
  285. PDEVOBJ pdevobj,
  286. POEMMEMORYUSAGE pMemoryUsage)
  287. {
  288. VERBOSE((DLLTEXT("IOemCB::MemoryUsage() entry.\n")));
  289. return E_NOTIMPL;
  290. }
  291. LONG __stdcall IOemCB::DownloadFontHeader(
  292. PDEVOBJ pdevobj,
  293. PUNIFONTOBJ pUFObj,
  294. OUT DWORD *pdwResult)
  295. {
  296. VERBOSE((DLLTEXT("IOemCB::DownloadFontHeader() entry.\n")));
  297. return E_NOTIMPL;
  298. }
  299. LONG __stdcall IOemCB::DownloadCharGlyph(
  300. PDEVOBJ pdevobj,
  301. PUNIFONTOBJ pUFObj,
  302. HGLYPH hGlyph,
  303. PDWORD pdwWidth,
  304. OUT DWORD *pdwResult)
  305. {
  306. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  307. return E_NOTIMPL;
  308. }
  309. LONG __stdcall IOemCB::TTDownloadMethod(
  310. PDEVOBJ pdevobj,
  311. PUNIFONTOBJ pUFObj,
  312. OUT DWORD *pdwResult)
  313. {
  314. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  315. return E_NOTIMPL;
  316. }
  317. LONG __stdcall IOemCB::OutputCharStr(
  318. PDEVOBJ pdevobj,
  319. PUNIFONTOBJ pUFObj,
  320. DWORD dwType,
  321. DWORD dwCount,
  322. PVOID pGlyph)
  323. {
  324. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  325. return E_NOTIMPL;
  326. }
  327. LONG __stdcall IOemCB::SendFontCmd(
  328. PDEVOBJ pdevobj,
  329. PUNIFONTOBJ pUFObj,
  330. PFINVOCATION pFInv)
  331. {
  332. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  333. return E_NOTIMPL;
  334. }
  335. LONG __stdcall IOemCB::DriverDMS(
  336. PVOID pDevObj,
  337. PVOID pBuffer,
  338. DWORD cbSize,
  339. PDWORD pcbNeeded)
  340. {
  341. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  342. return E_NOTIMPL;
  343. }
  344. LONG __stdcall IOemCB::TextOutAsBitmap(
  345. SURFOBJ *pso,
  346. STROBJ *pstro,
  347. FONTOBJ *pfo,
  348. CLIPOBJ *pco,
  349. RECTL *prclExtra,
  350. RECTL *prclOpaque,
  351. BRUSHOBJ *pboFore,
  352. BRUSHOBJ *pboOpaque,
  353. POINTL *pptlOrg,
  354. MIX mix)
  355. {
  356. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  357. return E_NOTIMPL;
  358. }
  359. LONG __stdcall IOemCB::TTYGetInfo(
  360. PDEVOBJ pdevobj,
  361. DWORD dwInfoIndex,
  362. PVOID pOutputBuf,
  363. DWORD dwSize,
  364. DWORD *pcbcNeeded)
  365. {
  366. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  367. return E_NOTIMPL;
  368. }
  369. ///////////////////////////////////////////////////////////
  370. //
  371. // Class factory body
  372. //
  373. HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv)
  374. {
  375. if (NULL == ppv)
  376. {
  377. return E_NOINTERFACE;
  378. }
  379. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  380. {
  381. *ppv = static_cast<IOemCF*>(this);
  382. }
  383. else
  384. {
  385. *ppv = NULL;
  386. return E_NOINTERFACE;
  387. }
  388. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  389. return S_OK ;
  390. }
  391. ULONG __stdcall IOemCF::AddRef()
  392. {
  393. return InterlockedIncrement(&m_cRef);
  394. }
  395. ULONG __stdcall IOemCF::Release()
  396. {
  397. if (InterlockedDecrement(&m_cRef) == 0)
  398. {
  399. delete this ;
  400. return 0 ;
  401. }
  402. return m_cRef ;
  403. }
  404. // IClassFactory implementation
  405. HRESULT __stdcall IOemCF::CreateInstance(IUnknown* pUnknownOuter,
  406. const IID& iid,
  407. void** ppv)
  408. {
  409. //VERBOSE((DLLTEXT("Class factory:\t\tCreate component.")));
  410. // Cannot aggregate.
  411. if (pUnknownOuter != NULL)
  412. {
  413. return CLASS_E_NOAGGREGATION ;
  414. }
  415. // Create component.
  416. IOemCB* pOemCB = new IOemCB ;
  417. if (pOemCB == NULL)
  418. {
  419. return E_OUTOFMEMORY ;
  420. }
  421. // Get the requested interface.
  422. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  423. // Release the IUnknown pointer.
  424. // (If QueryInterface failed, component will delete itself.)
  425. pOemCB->Release();
  426. return hr ;
  427. }
  428. // LockServer
  429. HRESULT __stdcall IOemCF::LockServer(BOOL bLock)
  430. {
  431. if (bLock)
  432. {
  433. InterlockedIncrement(&g_cServerLocks);
  434. }
  435. else
  436. {
  437. InterlockedDecrement(&g_cServerLocks);
  438. }
  439. return S_OK ;
  440. }
  441. ///////////////////////////////////////////////////////////
  442. //
  443. // Export functions
  444. //
  445. //
  446. // Registration functions
  447. // Testing purpose
  448. //
  449. //
  450. // Can DLL unload now?
  451. //
  452. STDAPI DllCanUnloadNow()
  453. {
  454. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  455. {
  456. return S_OK ;
  457. }
  458. else
  459. {
  460. return S_FALSE ;
  461. }
  462. }
  463. //
  464. // Get class factory
  465. //
  466. STDAPI DllGetClassObject(const CLSID& clsid,
  467. const IID& iid,
  468. void** ppv)
  469. {
  470. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  471. // Can we create this component?
  472. if (clsid != CLSID_OEMRENDER)
  473. {
  474. return CLASS_E_CLASSNOTAVAILABLE ;
  475. }
  476. // Create class factory.
  477. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  478. // in constructor
  479. if (pFontCF == NULL)
  480. {
  481. return E_OUTOFMEMORY ;
  482. }
  483. // Get requested interface.
  484. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  485. pFontCF->Release();
  486. return hr ;
  487. }