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.

329 lines
8.4 KiB

  1. /*=============================================================================
  2. * FILENAME: exports.cpp
  3. * Copyright (C) 1996-1998 HDE, Inc. All Rights Reserved. HDE Confidential.
  4. * Copyright (C) 1999 NEC Technologies, Inc. All Rights Reserved.
  5. *
  6. * DESCRIPTION: Contains exported functions required to get an OEM plug-in
  7. * to work.
  8. * NOTES:
  9. *=============================================================================
  10. */
  11. #include "precomp.h"
  12. #include <windows.h>
  13. #include <WINDDI.H>
  14. #include <PRINTOEM.H>
  15. #include <strsafe.h>
  16. #include "nc46nt.h"
  17. #include "oemps.h"
  18. /*
  19. For OEMEnableDriver
  20. */
  21. static const DRVFN OEMHookFuncs[] =
  22. {
  23. { INDEX_DrvStartDoc, (PFN) OEMStartDoc },
  24. { INDEX_DrvEndDoc, (PFN) OEMEndDoc },
  25. };
  26. /******************************************************************************
  27. * DESCRIPTION: Called by the postscript driver after the dll is loaded
  28. * to get plug-in information
  29. *
  30. *****************************************************************************/
  31. extern "C" BOOL APIENTRY
  32. OEMGetInfo( DWORD dwMode,
  33. PVOID pBuffer,
  34. DWORD cbSize,
  35. PDWORD pcbNeeded )
  36. {
  37. // Validate parameters.
  38. if( NULL == pcbNeeded )
  39. {
  40. EngSetLastError(ERROR_INVALID_PARAMETER);
  41. return FALSE;
  42. }
  43. // Set expected buffer size and number of bytes written.
  44. *pcbNeeded = sizeof(DWORD);
  45. // Check buffer size is sufficient.
  46. if((cbSize < *pcbNeeded) || (NULL == pBuffer))
  47. {
  48. EngSetLastError(ERROR_INSUFFICIENT_BUFFER);
  49. return FALSE;
  50. }
  51. switch(dwMode)
  52. {
  53. case OEMGI_GETSIGNATURE: // OEM DLL Signature
  54. *(PDWORD)pBuffer = OEM_SIGNATURE;
  55. break;
  56. case OEMGI_GETVERSION: // OEM DLL version
  57. *(PDWORD)pBuffer = OEM_VERSION;
  58. break;
  59. case OEMGI_GETINTERFACEVERSION: // version the Printer driver supports
  60. *(PDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  61. break;
  62. case OEMGI_GETPUBLISHERINFO: // fill PUBLISHERINFO structure
  63. // fall through to not supported
  64. default: // dwMode not supported.
  65. // Set written bytes to zero since nothing was written.
  66. *pcbNeeded = 0;
  67. EngSetLastError(ERROR_NOT_SUPPORTED);
  68. return FALSE;
  69. }
  70. return TRUE;
  71. }
  72. /******************************************************************************
  73. * DESCRIPTION: Exported function that allows setting of private and public
  74. * devmode fields.
  75. * NOTE: This function must be in entered under EXPORTS in rntapsui.def to be called
  76. *****************************************************************************/
  77. extern "C" BOOL APIENTRY
  78. OEMDevMode( DWORD dwMode, POEMDMPARAM pOemDMParam )
  79. {
  80. POEMDEV pOEMDevIn;
  81. POEMDEV pOEMDevOut;
  82. switch(dwMode) // kernel mode rendering dll
  83. {
  84. case OEMDM_SIZE: // size of oem devmode
  85. if( pOemDMParam )
  86. pOemDMParam->cbBufSize = sizeof( OEMDEV );
  87. break;
  88. case OEMDM_DEFAULT: // fill oem devmode with default data
  89. if( pOemDMParam && pOemDMParam->pOEMDMOut )
  90. {
  91. pOEMDevOut = (POEMDEV)pOemDMParam->pOEMDMOut;
  92. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
  93. pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
  94. pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
  95. }
  96. break;
  97. case OEMDM_MERGE: // set the public devmode fields
  98. case OEMDM_CONVERT: // convert any old oem devmode to new version
  99. if( pOemDMParam && pOemDMParam->pOEMDMOut && pOemDMParam->pOEMDMIn )
  100. {
  101. pOEMDevIn = (POEMDEV)pOemDMParam->pOEMDMIn;
  102. pOEMDevOut = (POEMDEV)pOemDMParam->pOEMDMOut;
  103. if( pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature )
  104. {
  105. // wcscpy( pOEMDevOut->szUserName, pOEMDevIn->szUserName );
  106. StringCbCopy( pOEMDevOut->szUserName, sizeof(pOEMDevOut->szUserName), pOEMDevIn->szUserName );
  107. }
  108. }
  109. break;
  110. }
  111. return( TRUE );
  112. }
  113. /******************************************************************************
  114. * DESCRIPTION: Windows dll required entry point function.
  115. *
  116. *****************************************************************************/
  117. extern "C"
  118. BOOL WINAPI DllInitialize(ULONG ulReason)
  119. {
  120. switch(ulReason)
  121. {
  122. case DLL_PROCESS_ATTACH:
  123. break;
  124. case DLL_THREAD_ATTACH:
  125. break;
  126. case DLL_PROCESS_DETACH:
  127. break;
  128. case DLL_THREAD_DETACH:
  129. break;
  130. }
  131. return( TRUE );
  132. }
  133. extern "C"
  134. VOID APIENTRY OEMDisableDriver()
  135. {
  136. // DebugMsg(DLLTEXT("OEMDisableDriver() entry.\r\n"));
  137. }
  138. extern "C"
  139. BOOL APIENTRY OEMEnableDriver(DWORD dwOEMintfVersion, DWORD dwSize, PDRVENABLEDATA pded)
  140. {
  141. // DebugMsg(DLLTEXT("OEMEnableDriver() entry.\r\n"));
  142. // List DDI functions that are hooked.
  143. pded->iDriverVersion = PRINTER_OEMINTF_VERSION;
  144. pded->c = sizeof(OEMHookFuncs) / sizeof(DRVFN);
  145. pded->pdrvfn = (DRVFN *) OEMHookFuncs;
  146. return TRUE;
  147. }
  148. extern "C"
  149. PDEVOEM APIENTRY OEMEnablePDEV(
  150. PDEVOBJ pdevobj,
  151. PWSTR pPrinterName,
  152. ULONG cPatterns,
  153. HSURF *phsurfPatterns,
  154. ULONG cjGdiInfo,
  155. GDIINFO *pGdiInfo,
  156. ULONG cjDevInfo,
  157. DEVINFO *pDevInfo,
  158. DRVENABLEDATA *pded // Unidrv's hook table
  159. )
  160. {
  161. POEMPDEV poempdev;
  162. INT i, j;
  163. DWORD dwDDIIndex;
  164. PDRVFN pdrvfn;
  165. //
  166. // Allocate the OEMDev
  167. //
  168. // poempdev = new OEMPDEV;
  169. poempdev = (POEMPDEV) EngAllocMem(FL_ZERO_MEMORY, sizeof(OEMPDEV), OEM_SIGNATURE);
  170. if (NULL == poempdev)
  171. {
  172. return NULL;
  173. }
  174. //
  175. // Allocate memory for poempdev->szDocName
  176. //
  177. poempdev->szDocName = (char *) EngAllocMem(FL_ZERO_MEMORY, NEC_DOCNAME_BUF_LEN+2, OEM_SIGNATURE);
  178. if (NULL == poempdev->szDocName)
  179. {
  180. return NULL;
  181. }
  182. /* MMM */
  183. //
  184. // Allocate memory for poempdev->pPrinterName
  185. poempdev->pPrinterName = (PWSTR) EngAllocMem(FL_ZERO_MEMORY, (wcslen(pPrinterName)+1)*sizeof(WCHAR), OEM_SIGNATURE);
  186. if (NULL == poempdev->pPrinterName)
  187. {
  188. return NULL;
  189. }
  190. /* MMM */
  191. //
  192. // Fill in OEMDEV as you need
  193. //
  194. // _tcscpy(poempdev->pPrinterName, pPrinterName); /* MMM */
  195. StringCbCopy( poempdev->pPrinterName, sizeof(poempdev->pPrinterName), pPrinterName);
  196. //
  197. // Fill in OEMDEV
  198. //
  199. for (i = 0; i < MAX_DDI_HOOKS; i++)
  200. {
  201. //
  202. // search through Unidrv's hooks and locate the function ptr
  203. //
  204. dwDDIIndex = OEMHookFuncs[i].iFunc;
  205. for (j = pded->c, pdrvfn = pded->pdrvfn; j > 0; j--, pdrvfn++)
  206. {
  207. if (dwDDIIndex == pdrvfn->iFunc)
  208. {
  209. poempdev->pfnPS[i] = pdrvfn->pfn;
  210. break;
  211. }
  212. }
  213. if (j == 0)
  214. {
  215. //
  216. // didn't find the Unidrv hook. Should happen only with DrvRealizeBrush
  217. //
  218. poempdev->pfnPS[i] = NULL;
  219. }
  220. }
  221. return (POEMPDEV) poempdev;
  222. }
  223. extern "C"
  224. VOID APIENTRY OEMDisablePDEV(
  225. PDEVOBJ pdevobj
  226. )
  227. {
  228. // DebugMsg(DLLTEXT("OEMDisablePDEV() entry.\r\n"));
  229. POEMPDEV poempdev = (POEMPDEV) pdevobj->pdevOEM;
  230. //
  231. // Free memory for OEMPDEV and any memory block that hangs off OEMPDEV.
  232. //
  233. if(NULL != poempdev->szDocName)
  234. {
  235. EngFreeMem(poempdev->szDocName);
  236. poempdev->szDocName = (char *)NULL;
  237. }
  238. /* MMM */
  239. if(NULL != poempdev->pPrinterName)
  240. {
  241. EngFreeMem(poempdev->pPrinterName);
  242. poempdev->pPrinterName = (PWSTR)NULL;
  243. }
  244. /* MMM */
  245. assert(NULL != pdevobj->pdevOEM);
  246. // delete pdevobj->pdevOEM;
  247. EngFreeMem(pdevobj->pdevOEM);
  248. }
  249. extern "C"
  250. BOOL APIENTRY OEMResetPDEV(
  251. PDEVOBJ pdevobjOld,
  252. PDEVOBJ pdevobjNew
  253. )
  254. {
  255. POEMPDEV poempdevOld = (POEMPDEV)pdevobjOld->pdevOEM;
  256. POEMPDEV poempdevNew = (POEMPDEV)pdevobjNew->pdevOEM;
  257. if((NULL != poempdevNew->szDocName) && (NULL != poempdevOld->szDocName))
  258. {
  259. strncpy(poempdevNew->szDocName, poempdevOld->szDocName, NEC_DOCNAME_BUF_LEN);
  260. }
  261. //
  262. // If you want to carry over anything from old pdev to new pdev, do it here.
  263. //
  264. return TRUE;
  265. }