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.

609 lines
14 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. // NTRAID#NTBUG9-588573-2002/03/28-v-sueyas-: Correct the return values for each COM I/F methods
  14. #ifdef USERMODE_DRIVER
  15. #define INITGUID // for GUID one-time initialization
  16. #include "fmlbp.h"
  17. #include "name.h"
  18. // Globals
  19. static HMODULE g_hModule = NULL ; // DLL module handle
  20. static long g_cComponents = 0 ; // Count of active components
  21. static long g_cServerLocks = 0 ; // Count of locks
  22. #include "comoem.h"
  23. ////////////////////////////////////////////////////////////////////////////////
  24. //
  25. // IOemCB body
  26. //
  27. HRESULT __stdcall IOemCB::QueryInterface(const IID& iid, void** ppv)
  28. {
  29. // DbgPrint(DLLTEXT("IOemCB: QueryInterface entry\n"));
  30. // NTRAID#NTBUG9-587382-2002/03/27-v-sueyas-: Check for illegal parameters
  31. if (NULL == ppv)
  32. return E_NOINTERFACE;
  33. if (iid == IID_IUnknown)
  34. {
  35. *ppv = static_cast<IUnknown*>(this);
  36. // DbgPrint(DLLTEXT("IOemCB:Return pointer to IUnknown.\n")) ;
  37. }
  38. else if (iid == IID_IPrintOemUni)
  39. {
  40. *ppv = static_cast<IPrintOemUni*>(this) ;
  41. // DbgPrint(DLLTEXT("IOemCB:Return pointer to IPrintOemUni.\n")) ;
  42. }
  43. else
  44. {
  45. *ppv = NULL ;
  46. // DbgPrint(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. // DbgPrint(DLLTEXT("IOemCB::AddRef() entry.\r\n"));
  55. return InterlockedIncrement(&m_cRef) ;
  56. }
  57. ULONG __stdcall IOemCB::Release()
  58. {
  59. // DbgPrint(DLLTEXT("IOemCB::Release() entry.\r\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. // DbgPrint(DLLTEXT("IOemCB::EnableDriver() entry.\r\n"));
  72. // Sep.17.98 ->
  73. // OEMEnableDriver(dwDriverVersion, cbSize, pded);
  74. // Need to return S_OK so that DisableDriver() will be called, which Releases
  75. // the reference to the Printer Driver's interface.
  76. return S_OK;
  77. // Sep.17.98 <-
  78. }
  79. LONG __stdcall IOemCB::DisableDriver(VOID)
  80. {
  81. // DbgPrint(DLLTEXT("IOemCB::DisaleDriver() entry.\r\n"));
  82. // Sep.17.98 ->
  83. // OEMDisableDriver();
  84. // Release reference to Printer Driver's interface.
  85. if (this->pOEMHelp)
  86. {
  87. this->pOEMHelp->Release();
  88. this->pOEMHelp = NULL;
  89. }
  90. return S_OK;
  91. // Sep.17.98 <-
  92. }
  93. LONG __stdcall IOemCB::PublishDriverInterface(
  94. IUnknown *pIUnknown)
  95. {
  96. // DbgPrint(DLLTEXT("IOemCB::PublishDriverInterface() entry.\r\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. LONG __stdcall IOemCB::EnablePDEV(
  115. PDEVOBJ pdevobj,
  116. PWSTR pPrinterName,
  117. ULONG cPatterns,
  118. HSURF *phsurfPatterns,
  119. ULONG cjGdiInfo,
  120. GDIINFO *pGdiInfo,
  121. ULONG cjDevInfo,
  122. DEVINFO *pDevInfo,
  123. DRVENABLEDATA *pded,
  124. OUT PDEVOEM *pDevOem)
  125. {
  126. // DbgPrint(DLLTEXT("IOemCB::EnablePDEV() entry.\r\n"));
  127. // NTRAID#NTBUG9-587382-2002/03/27-v-sueyas-: Check for illegal parameters
  128. if (NULL == pDevOem)
  129. return E_FAIL;
  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. LONG lI;
  150. // DbgPrint(DLLTEXT("IOemCB::DisablePDEV() entry.\r\n"));
  151. OEMDisablePDEV(pdevobj);
  152. return S_OK;
  153. }
  154. LONG __stdcall IOemCB::GetInfo (
  155. DWORD dwMode,
  156. PVOID pBuffer,
  157. DWORD cbSize,
  158. PDWORD pcbNeeded)
  159. {
  160. // DbgPrint(DLLTEXT("IOemCB::GetInfo() entry.\r\n"));
  161. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  162. return S_OK;
  163. else
  164. return E_FAIL;
  165. }
  166. LONG __stdcall IOemCB::GetImplementedMethod(
  167. PSTR pMethodName)
  168. {
  169. LONG lReturn;
  170. // DbgPrint(DLLTEXT("IOemCB::GetImplementedMethod() entry.\r\n"));
  171. // DbgPrint(DLLTEXT(" Function:%s:"),pMethodName);
  172. lReturn = FALSE;
  173. if (pMethodName == NULL)
  174. {
  175. }
  176. else
  177. {
  178. switch (*pMethodName)
  179. {
  180. case (WCHAR)'C':
  181. if (!strcmp(pstrCommandCallback, pMethodName))
  182. lReturn = TRUE;
  183. break;
  184. case (WCHAR)'D':
  185. if (!strcmp(pstrDisablePDEV, pMethodName))
  186. lReturn = TRUE;
  187. else if (!strcmp(pstrDevMode, pMethodName))
  188. lReturn = TRUE;
  189. break;
  190. case (WCHAR)'E':
  191. if (!strcmp(pstrEnablePDEV, pMethodName))
  192. lReturn = TRUE;
  193. break;
  194. case (WCHAR)'F':
  195. break;
  196. case (WCHAR)'G':
  197. if (!strcmp(pstrGetInfo, pMethodName))
  198. lReturn = TRUE;
  199. break;
  200. case (WCHAR)'H':
  201. break;
  202. case (WCHAR)'I':
  203. break;
  204. case (WCHAR)'M':
  205. break;
  206. case (WCHAR)'O':
  207. if (!strcmp(pstrOutputCharStr, pMethodName))
  208. lReturn = TRUE;
  209. break;
  210. case (WCHAR)'R':
  211. if (!strcmp(pstrResetPDEV, pMethodName))
  212. lReturn = TRUE;
  213. break;
  214. case (WCHAR)'S':
  215. if (!strcmp(pstrSendFontCmd, pMethodName))
  216. lReturn = TRUE;
  217. break;
  218. case (WCHAR)'T':
  219. break;
  220. }
  221. }
  222. if (lReturn)
  223. {
  224. // DbgPrint(__TEXT("Supported\r\n"));
  225. return S_OK;
  226. }
  227. else
  228. {
  229. // DbgPrint(__TEXT("NOT supported\r\n"));
  230. return E_FAIL;
  231. }
  232. }
  233. LONG __stdcall IOemCB::DevMode(
  234. DWORD dwMode,
  235. POEMDMPARAM pOemDMParam)
  236. {
  237. // DbgPrint(DLLTEXT("IOemCB::DevMode() entry.\r\n"));
  238. if (OEMDevMode(dwMode, pOemDMParam))
  239. return S_OK;
  240. else
  241. return E_FAIL;
  242. }
  243. LONG __stdcall IOemCB::CommandCallback(
  244. PDEVOBJ pdevobj,
  245. DWORD dwCallbackID,
  246. DWORD dwCount,
  247. PDWORD pdwParams,
  248. OUT INT *piResult)
  249. {
  250. // DbgPrint(DLLTEXT("IOemCB::CommandCallback() entry.\r\n"));
  251. // NTRAID#NTBUG9-587382-2002/03/27-v-sueyas-: Check for illegal parameters
  252. if (NULL == piResult)
  253. return E_FAIL;
  254. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  255. return S_OK;
  256. }
  257. LONG __stdcall IOemCB::ImageProcessing(
  258. PDEVOBJ pdevobj,
  259. PBYTE pSrcBitmap,
  260. PBITMAPINFOHEADER pBitmapInfoHeader,
  261. PBYTE pColorTable,
  262. DWORD dwCallbackID,
  263. PIPPARAMS pIPParams,
  264. OUT PBYTE *ppbResult)
  265. {
  266. // DbgPrint(DLLTEXT("IOemCB::ImageProcessing() entry.\r\n"));
  267. return E_NOTIMPL;
  268. }
  269. LONG __stdcall IOemCB::FilterGraphics(
  270. PDEVOBJ pdevobj,
  271. PBYTE pBuf,
  272. DWORD dwLen)
  273. {
  274. // DbgPrint(DLLTEXT("IOemCB::FilterGraphis() entry.\r\n"));
  275. return E_NOTIMPL;
  276. }
  277. LONG __stdcall IOemCB::Compression(
  278. PDEVOBJ pdevobj,
  279. PBYTE pInBuf,
  280. PBYTE pOutBuf,
  281. DWORD dwInLen,
  282. DWORD dwOutLen,
  283. OUT INT *piResult)
  284. {
  285. // DbgPrint(DLLTEXT("IOemCB::Compression() entry.\r\n"));
  286. return E_NOTIMPL;
  287. }
  288. LONG __stdcall IOemCB::HalftonePattern(
  289. PDEVOBJ pdevobj,
  290. PBYTE pHTPattern,
  291. DWORD dwHTPatternX,
  292. DWORD dwHTPatternY,
  293. DWORD dwHTNumPatterns,
  294. DWORD dwCallbackID,
  295. PBYTE pResource,
  296. DWORD dwResourceSize)
  297. {
  298. // DbgPrint(DLLTEXT("IOemCB::HalftonePattern() entry.\r\n"));
  299. return E_NOTIMPL;
  300. }
  301. LONG __stdcall IOemCB::MemoryUsage(
  302. PDEVOBJ pdevobj,
  303. POEMMEMORYUSAGE pMemoryUsage)
  304. {
  305. // DbgPrint(DLLTEXT("IOemCB::MemoryUsage() entry.\r\n"));
  306. return E_NOTIMPL;
  307. }
  308. LONG __stdcall IOemCB::DownloadFontHeader(
  309. PDEVOBJ pdevobj,
  310. PUNIFONTOBJ pUFObj,
  311. OUT DWORD *pdwResult)
  312. {
  313. // DbgPrint(DLLTEXT("IOemCB::DownloadFontHeader() entry.\r\n"));
  314. return E_NOTIMPL;
  315. }
  316. LONG __stdcall IOemCB::DownloadCharGlyph(
  317. PDEVOBJ pdevobj,
  318. PUNIFONTOBJ pUFObj,
  319. HGLYPH hGlyph,
  320. PDWORD pdwWidth,
  321. OUT DWORD *pdwResult)
  322. {
  323. // DbgPrint(DLLTEXT("IOemCB::DownloadCharGlyph() entry.\r\n"));
  324. return E_NOTIMPL;
  325. }
  326. LONG __stdcall IOemCB::TTDownloadMethod(
  327. PDEVOBJ pdevobj,
  328. PUNIFONTOBJ pUFObj,
  329. OUT DWORD *pdwResult)
  330. {
  331. // DbgPrint(DLLTEXT("IOemCB::TTDownloadMethod() entry.\r\n"));
  332. return E_NOTIMPL;
  333. }
  334. LONG __stdcall IOemCB::OutputCharStr(
  335. PDEVOBJ pdevobj,
  336. PUNIFONTOBJ pUFObj,
  337. DWORD dwType,
  338. DWORD dwCount,
  339. PVOID pGlyph)
  340. {
  341. // DbgPrint(DLLTEXT("IOemCB::OutputCharStr() entry.\r\n"));
  342. // NTRAID#NTBUG9-587382-2002/03/27-v-sueyas-: Error handling
  343. if (bOEMOutputCharStr(pdevobj, pUFObj, dwType, dwCount, pGlyph))
  344. return S_OK;
  345. else
  346. return E_FAIL;
  347. }
  348. LONG __stdcall IOemCB::SendFontCmd(
  349. PDEVOBJ pdevobj,
  350. PUNIFONTOBJ pUFObj,
  351. PFINVOCATION pFInv)
  352. {
  353. // DbgPrint(DLLTEXT("IOemCB::SendFontCmd() entry.\r\n"));
  354. // NTRAID#NTBUG9-587382-2002/03/27-v-sueyas-: Error handling
  355. if (bOEMSendFontCmd(pdevobj, pUFObj, pFInv))
  356. return S_OK;
  357. else
  358. return E_FAIL;
  359. }
  360. LONG __stdcall IOemCB::DriverDMS(
  361. PVOID pDevObj,
  362. PVOID pBuffer,
  363. DWORD cbSize,
  364. PDWORD pcbNeeded)
  365. {
  366. // DbgPrint(DLLTEXT("IOemCB::DriverDMS() entry.\r\n"));
  367. return E_NOTIMPL;
  368. }
  369. LONG __stdcall IOemCB::TextOutAsBitmap(
  370. SURFOBJ *pso,
  371. STROBJ *pstro,
  372. FONTOBJ *pfo,
  373. CLIPOBJ *pco,
  374. RECTL *prclExtra,
  375. RECTL *prclOpaque,
  376. BRUSHOBJ *pboFore,
  377. BRUSHOBJ *pboOpaque,
  378. POINTL *pptlOrg,
  379. MIX mix)
  380. {
  381. // DbgPrint(DLLTEXT("IOemCB::TextOutAsBitmap() entry.\r\n"));
  382. return E_NOTIMPL;
  383. }
  384. LONG __stdcall IOemCB::TTYGetInfo(
  385. PDEVOBJ pdevobj,
  386. DWORD dwInfoIndex,
  387. PVOID pOutputBuf,
  388. DWORD dwSize,
  389. DWORD *pcbcNeeded)
  390. {
  391. // DbgPrint(DLLTEXT("IOemCB::TTYGetInfo() entry.\r\n"));
  392. return E_NOTIMPL;
  393. }
  394. ///////////////////////////////////////////////////////////
  395. //
  396. // Class factory body
  397. //
  398. HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv)
  399. {
  400. // NTRAID#NTBUG9-587382-2002/03/27-v-sueyas-: Check for illegal parameters
  401. if (NULL == ppv)
  402. return E_NOINTERFACE;
  403. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  404. {
  405. *ppv = static_cast<IOemCF*>(this);
  406. }
  407. else
  408. {
  409. *ppv = NULL ;
  410. return E_NOINTERFACE ;
  411. }
  412. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  413. return S_OK ;
  414. }
  415. ULONG __stdcall IOemCF::AddRef()
  416. {
  417. return InterlockedIncrement(&m_cRef) ;
  418. }
  419. ULONG __stdcall IOemCF::Release()
  420. {
  421. if (InterlockedDecrement(&m_cRef) == 0)
  422. {
  423. delete this ;
  424. return 0 ;
  425. }
  426. return m_cRef ;
  427. }
  428. // IClassFactory implementation
  429. HRESULT __stdcall IOemCF::CreateInstance(IUnknown* pUnknownOuter,
  430. const IID& iid,
  431. void** ppv)
  432. {
  433. //// DbgPrint(DLLTEXT("Class factory:\t\tCreate component.")) ;
  434. // Cannot aggregate.
  435. if (pUnknownOuter != NULL)
  436. {
  437. return CLASS_E_NOAGGREGATION ;
  438. }
  439. // Create component.
  440. IOemCB* pOemCB = new IOemCB ;
  441. if (pOemCB == NULL)
  442. {
  443. return E_OUTOFMEMORY ;
  444. }
  445. // Get the requested interface.
  446. HRESULT hr = pOemCB->QueryInterface(iid, ppv) ;
  447. // Release the IUnknown pointer.
  448. // (If QueryInterface failed, component will delete itself.)
  449. pOemCB->Release() ;
  450. return hr ;
  451. }
  452. // LockServer
  453. HRESULT __stdcall IOemCF::LockServer(BOOL bLock)
  454. {
  455. if (bLock)
  456. {
  457. InterlockedIncrement(&g_cServerLocks) ;
  458. }
  459. else
  460. {
  461. InterlockedDecrement(&g_cServerLocks) ;
  462. }
  463. return S_OK ;
  464. }
  465. ///////////////////////////////////////////////////////////
  466. //
  467. // Export functions
  468. //
  469. //
  470. // Registration functions
  471. // Testing purpose
  472. //
  473. //
  474. // Can DLL unload now?
  475. //
  476. STDAPI DllCanUnloadNow()
  477. {
  478. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  479. {
  480. return S_OK ;
  481. }
  482. else
  483. {
  484. return S_FALSE ;
  485. }
  486. }
  487. //
  488. // Get class factory
  489. //
  490. STDAPI DllGetClassObject(const CLSID& clsid,
  491. const IID& iid,
  492. void** ppv)
  493. {
  494. //// DbgPrint(DLLTEXT("DllGetClassObject:\tCreate class factory.")) ;
  495. // Can we create this component?
  496. if (clsid != CLSID_OEMRENDER)
  497. {
  498. return CLASS_E_CLASSNOTAVAILABLE ;
  499. }
  500. // Create class factory.
  501. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  502. // in constructor
  503. if (pFontCF == NULL)
  504. {
  505. return E_OUTOFMEMORY ;
  506. }
  507. // Get requested interface.
  508. HRESULT hr = pFontCF->QueryInterface(iid, ppv) ;
  509. pFontCF->Release() ;
  510. return hr ;
  511. }
  512. #endif // USERMODE_DRIVER