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.

631 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-588581-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-581700-2002/03/19-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. return E_NOTIMPL;
  127. }
  128. LONG __stdcall IOemCB::ResetPDEV(
  129. PDEVOBJ pdevobjOld,
  130. PDEVOBJ pdevobjNew)
  131. {
  132. return E_NOTIMPL;
  133. }
  134. LONG __stdcall IOemCB::DisablePDEV(
  135. PDEVOBJ pdevobj)
  136. {
  137. LONG lI;
  138. VERBOSE((DLLTEXT("IOemCB::DisablePDEV() entry.\n")));
  139. return E_NOTIMPL;
  140. }
  141. LONG __stdcall IOemCB::GetInfo (
  142. DWORD dwMode,
  143. PVOID pBuffer,
  144. DWORD cbSize,
  145. PDWORD pcbNeeded)
  146. {
  147. VERBOSE((DLLTEXT("IOemCB::GetInfo() entry.\n")));
  148. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  149. return S_OK;
  150. else
  151. return E_FAIL;
  152. }
  153. LONG __stdcall IOemCB::GetImplementedMethod(
  154. PSTR pMethodName)
  155. {
  156. LONG lReturn;
  157. VERBOSE((DLLTEXT("IOemCB::GetImplementedMethod() entry.\n")));
  158. VERBOSE((DLLTEXT(" Function:%s:"),pMethodName));
  159. lReturn = FALSE;
  160. if (pMethodName == NULL)
  161. {
  162. }
  163. else
  164. {
  165. switch (*pMethodName)
  166. {
  167. case (WCHAR)'C':
  168. if (!strcmp(pstrCommandCallback, pMethodName))
  169. lReturn = TRUE;
  170. else if (!strcmp(pstrCompression, pMethodName))
  171. lReturn = TRUE;
  172. break;
  173. case (WCHAR)'D':
  174. if (!strcmp(pstrDisableDriver, pMethodName))
  175. lReturn = TRUE;
  176. else if (!strcmp(pstrDisablePDEV, pMethodName))
  177. lReturn = TRUE;
  178. else if (!strcmp(pstrDriverDMS, pMethodName))
  179. lReturn = TRUE;
  180. if (!strcmp(pstrDevMode, pMethodName))
  181. lReturn = TRUE;
  182. else if (!strcmp(pstrDownloadFontHeader, pMethodName))
  183. lReturn = TRUE;
  184. else if (!strcmp(pstrDownloadCharGlyph, pMethodName))
  185. lReturn = TRUE;
  186. break;
  187. case (WCHAR)'E':
  188. if (!strcmp(pstrEnableDriver, pMethodName))
  189. lReturn = TRUE;
  190. else if (!strcmp(pstrEnablePDEV, pMethodName))
  191. lReturn = TRUE;
  192. break;
  193. case (WCHAR)'F':
  194. if (!strcmp(pstrFilterGraphics, pMethodName))
  195. lReturn = TRUE;
  196. break;
  197. case (WCHAR)'G':
  198. if (!strcmp(pstrGetInfo, pMethodName))
  199. lReturn = TRUE;
  200. break;
  201. case (WCHAR)'H':
  202. if (!strcmp(pstrHalftonePattern, pMethodName))
  203. lReturn = TRUE;
  204. break;
  205. case (WCHAR)'I':
  206. if (!strcmp(pstrImageProcessing, pMethodName))
  207. lReturn = TRUE;
  208. break;
  209. case (WCHAR)'M':
  210. if (!strcmp(pstrMemoryUsage, pMethodName))
  211. lReturn = TRUE;
  212. break;
  213. case (WCHAR)'O':
  214. if (!strcmp(pstrOutputCharStr, pMethodName))
  215. lReturn = TRUE;
  216. break;
  217. case (WCHAR)'R':
  218. if (!strcmp(pstrResetPDEV, pMethodName))
  219. lReturn = TRUE;
  220. break;
  221. case (WCHAR)'S':
  222. if (!strcmp(pstrSendFontCmd, pMethodName))
  223. lReturn = TRUE;
  224. break;
  225. case (WCHAR)'T':
  226. if (!strcmp(pstrTextOutAsBitmap, pMethodName))
  227. lReturn = TRUE;
  228. else
  229. if (!strcmp(pstrTTDownloadMethod, pMethodName))
  230. lReturn = TRUE;
  231. else if (!strcmp(pstrTTYGetInfo, pMethodName))
  232. lReturn = TRUE;
  233. break;
  234. }
  235. }
  236. if (lReturn)
  237. {
  238. VERBOSE(("Supported\n"));
  239. return S_OK;
  240. }
  241. else
  242. {
  243. VERBOSE(("NOT supported\n"));
  244. return E_FAIL;
  245. }
  246. }
  247. LONG __stdcall IOemCB::DevMode(
  248. DWORD dwMode,
  249. POEMDMPARAM pOemDMParam)
  250. {
  251. VERBOSE((DLLTEXT("IOemCB::DevMode() entry.\n")));
  252. if (OEMDevMode(dwMode, pOemDMParam))
  253. return S_OK;
  254. else
  255. return E_FAIL;
  256. }
  257. LONG __stdcall IOemCB::CommandCallback(
  258. PDEVOBJ pdevobj,
  259. DWORD dwCallbackID,
  260. DWORD dwCount,
  261. PDWORD pdwParams,
  262. OUT INT *piResult)
  263. {
  264. VERBOSE((DLLTEXT("IOemCB::CommandCallback() entry.\n")));
  265. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  266. if (NULL == piResult)
  267. return E_FAIL;
  268. *piResult = OEMCommandCallback(pdevobj, dwCallbackID, dwCount, pdwParams);
  269. return S_OK;
  270. }
  271. LONG __stdcall IOemCB::ImageProcessing(
  272. PDEVOBJ pdevobj,
  273. PBYTE pSrcBitmap,
  274. PBITMAPINFOHEADER pBitmapInfoHeader,
  275. PBYTE pColorTable,
  276. DWORD dwCallbackID,
  277. PIPPARAMS pIPParams,
  278. OUT PBYTE *ppbResult)
  279. {
  280. VERBOSE((DLLTEXT("IOemCB::ImageProcessing() entry.\n")));
  281. return E_NOTIMPL;
  282. }
  283. LONG __stdcall IOemCB::FilterGraphics(
  284. PDEVOBJ pdevobj,
  285. PBYTE pBuf,
  286. DWORD dwLen)
  287. {
  288. VERBOSE((DLLTEXT("IOemCB::FilterGraphis() entry.\n")));
  289. if(OEMFilterGraphics(pdevobj, pBuf, dwLen))
  290. return S_OK;
  291. else
  292. return E_FAIL;
  293. }
  294. LONG __stdcall IOemCB::Compression(
  295. PDEVOBJ pdevobj,
  296. PBYTE pInBuf,
  297. PBYTE pOutBuf,
  298. DWORD dwInLen,
  299. DWORD dwOutLen,
  300. OUT INT *piResult)
  301. {
  302. VERBOSE((DLLTEXT("IOemCB::Compression() entry.\n")));
  303. return E_NOTIMPL;
  304. }
  305. LONG __stdcall IOemCB::HalftonePattern(
  306. PDEVOBJ pdevobj,
  307. PBYTE pHTPattern,
  308. DWORD dwHTPatternX,
  309. DWORD dwHTPatternY,
  310. DWORD dwHTNumPatterns,
  311. DWORD dwCallbackID,
  312. PBYTE pResource,
  313. DWORD dwResourceSize)
  314. {
  315. VERBOSE((DLLTEXT("IOemCB::HalftonePattern() entry.\n")));
  316. return E_NOTIMPL;
  317. }
  318. LONG __stdcall IOemCB::MemoryUsage(
  319. PDEVOBJ pdevobj,
  320. POEMMEMORYUSAGE pMemoryUsage)
  321. {
  322. VERBOSE((DLLTEXT("IOemCB::MemoryUsage() entry.\n")));
  323. return E_NOTIMPL;
  324. }
  325. LONG __stdcall IOemCB::DownloadFontHeader(
  326. PDEVOBJ pdevobj,
  327. PUNIFONTOBJ pUFObj,
  328. OUT DWORD *pdwResult)
  329. {
  330. VERBOSE((DLLTEXT("IOemCB::DownloadFontHeader() entry.\n")));
  331. return E_NOTIMPL;
  332. }
  333. LONG __stdcall IOemCB::DownloadCharGlyph(
  334. PDEVOBJ pdevobj,
  335. PUNIFONTOBJ pUFObj,
  336. HGLYPH hGlyph,
  337. PDWORD pdwWidth,
  338. OUT DWORD *pdwResult)
  339. {
  340. VERBOSE((DLLTEXT("IOemCB::DownloadCharGlyph() entry.\n")));
  341. return E_NOTIMPL;
  342. }
  343. LONG __stdcall IOemCB::TTDownloadMethod(
  344. PDEVOBJ pdevobj,
  345. PUNIFONTOBJ pUFObj,
  346. OUT DWORD *pdwResult)
  347. {
  348. VERBOSE((DLLTEXT("IOemCB::TTDownloadMethod() entry.\n")));
  349. return E_NOTIMPL;
  350. }
  351. LONG __stdcall IOemCB::OutputCharStr(
  352. PDEVOBJ pdevobj,
  353. PUNIFONTOBJ pUFObj,
  354. DWORD dwType,
  355. DWORD dwCount,
  356. PVOID pGlyph)
  357. {
  358. VERBOSE((DLLTEXT("IOemCB::OutputCharStr() entry.\n")));
  359. // NTRAID#NTBUG9-581704-2002/03/19-v-sueyas-: Error handling
  360. if (bOEMOutputCharStr(pdevobj, pUFObj, dwType, dwCount, pGlyph))
  361. return S_OK;
  362. else
  363. return E_FAIL;
  364. }
  365. LONG __stdcall IOemCB::SendFontCmd(
  366. PDEVOBJ pdevobj,
  367. PUNIFONTOBJ pUFObj,
  368. PFINVOCATION pFInv)
  369. {
  370. VERBOSE((DLLTEXT("IOemCB::SendFontCmd() entry.\n")));
  371. // NTRAID#NTBUG9-581704-2002/03/19-v-sueyas-: Error handling
  372. if (bOEMSendFontCmd(pdevobj, pUFObj, pFInv))
  373. return S_OK;
  374. else
  375. return E_FAIL;
  376. }
  377. LONG __stdcall IOemCB::DriverDMS(
  378. PVOID pDevObj,
  379. PVOID pBuffer,
  380. DWORD cbSize,
  381. PDWORD pcbNeeded)
  382. {
  383. VERBOSE((DLLTEXT("IOemCB::DriverDMS() entry.\n")));
  384. return E_NOTIMPL;
  385. }
  386. LONG __stdcall IOemCB::TextOutAsBitmap(
  387. SURFOBJ *pso,
  388. STROBJ *pstro,
  389. FONTOBJ *pfo,
  390. CLIPOBJ *pco,
  391. RECTL *prclExtra,
  392. RECTL *prclOpaque,
  393. BRUSHOBJ *pboFore,
  394. BRUSHOBJ *pboOpaque,
  395. POINTL *pptlOrg,
  396. MIX mix)
  397. {
  398. VERBOSE((DLLTEXT("IOemCB::TextOutAsBitmap() entry.\n")));
  399. return E_NOTIMPL;
  400. }
  401. LONG __stdcall IOemCB::TTYGetInfo(
  402. PDEVOBJ pdevobj,
  403. DWORD dwInfoIndex,
  404. PVOID pOutputBuf,
  405. DWORD dwSize,
  406. DWORD *pcbcNeeded)
  407. {
  408. VERBOSE((DLLTEXT("IOemCB::TTYGetInfo() entry.\n")));
  409. return E_NOTIMPL;
  410. }
  411. ///////////////////////////////////////////////////////////
  412. //
  413. // Class factory body
  414. //
  415. HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv)
  416. {
  417. // NTRAID#NTBUG9-581700-2002/03/19-v-sueyas-: Check for illegal parameters
  418. if (NULL == ppv)
  419. return E_NOINTERFACE;
  420. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  421. {
  422. *ppv = static_cast<IOemCF*>(this);
  423. }
  424. else
  425. {
  426. *ppv = NULL ;
  427. return E_NOINTERFACE ;
  428. }
  429. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  430. return S_OK ;
  431. }
  432. ULONG __stdcall IOemCF::AddRef()
  433. {
  434. return InterlockedIncrement(&m_cRef);
  435. }
  436. ULONG __stdcall IOemCF::Release()
  437. {
  438. if (InterlockedDecrement(&m_cRef) == 0)
  439. {
  440. delete this ;
  441. return 0 ;
  442. }
  443. return m_cRef ;
  444. }
  445. // IClassFactory implementation
  446. HRESULT __stdcall IOemCF::CreateInstance(IUnknown* pUnknownOuter,
  447. const IID& iid,
  448. void** ppv)
  449. {
  450. //VERBOSE((DLLTEXT("Class factory:\t\tCreate component.")));
  451. // Cannot aggregate.
  452. if (pUnknownOuter != NULL)
  453. {
  454. return CLASS_E_NOAGGREGATION ;
  455. }
  456. // Create component.
  457. IOemCB* pOemCB = new IOemCB ;
  458. if (pOemCB == NULL)
  459. {
  460. return E_OUTOFMEMORY ;
  461. }
  462. // Get the requested interface.
  463. HRESULT hr = pOemCB->QueryInterface(iid, ppv);
  464. // Release the IUnknown pointer.
  465. // (If QueryInterface failed, component will delete itself.)
  466. pOemCB->Release();
  467. return hr ;
  468. }
  469. // LockServer
  470. HRESULT __stdcall IOemCF::LockServer(BOOL bLock)
  471. {
  472. if (bLock)
  473. {
  474. InterlockedIncrement(&g_cServerLocks);
  475. }
  476. else
  477. {
  478. InterlockedDecrement(&g_cServerLocks);
  479. }
  480. return S_OK ;
  481. }
  482. ///////////////////////////////////////////////////////////
  483. //
  484. // Export functions
  485. //
  486. //
  487. // Registration functions
  488. // Testing purpose
  489. //
  490. //
  491. // Can DLL unload now?
  492. //
  493. STDAPI DllCanUnloadNow()
  494. {
  495. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  496. {
  497. return S_OK ;
  498. }
  499. else
  500. {
  501. return S_FALSE ;
  502. }
  503. }
  504. //
  505. // Get class factory
  506. //
  507. STDAPI DllGetClassObject(const CLSID& clsid,
  508. const IID& iid,
  509. void** ppv)
  510. {
  511. //VERBOSE((DLLTEXT("DllGetClassObject:\tCreate class factory.")));
  512. // Can we create this component?
  513. if (clsid != CLSID_OEMRENDER)
  514. {
  515. return CLASS_E_CLASSNOTAVAILABLE ;
  516. }
  517. // Create class factory.
  518. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  519. // in constructor
  520. if (pFontCF == NULL)
  521. {
  522. return E_OUTOFMEMORY ;
  523. }
  524. // Get requested interface.
  525. HRESULT hr = pFontCF->QueryInterface(iid, ppv);
  526. pFontCF->Release();
  527. return hr ;
  528. }