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.

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