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.

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