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.

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