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.

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