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.

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