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.

403 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. umpdeng.c
  5. Abstract:
  6. User-mode printer driver stubs for Eng callback functions
  7. Environment:
  8. Windows NT 5.0
  9. Revision History:
  10. 07/23/97 -lingyunw-
  11. Created it.
  12. 10/28/97 -davidx-
  13. Combine umpdeng.c and ddiglue.c into a single file.
  14. 10/28/97 -lingyunw-
  15. Move straight Eng to NtGdiEng calls etc to gdi32.def.
  16. --*/
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. #include "winddi.h"
  20. #if !defined(_GDIPLUS_)
  21. //
  22. // Functions to get information about driver DLLs
  23. //
  24. // anyway, before we return back from DrvEnablePDEV, our
  25. // pdev->dhpdev points to pUMPD, only after returning, we
  26. // ppdev->dhpdev points to pUMdhpdev
  27. //
  28. LPWSTR
  29. EngGetPrinterDataFileName(
  30. HDEV hdev
  31. )
  32. {
  33. PUMPD pUMPD;
  34. if ((pUMPD = (PUMPD) NtGdiGetDhpdev(hdev)) == NULL)
  35. return NULL;
  36. if (pUMPD->dwSignature != UMPD_SIGNATURE)
  37. pUMPD = ((PUMDHPDEV) pUMPD)->pUMPD;
  38. return pUMPD->pDriverInfo2->pDataFile;
  39. }
  40. LPWSTR
  41. EngGetDriverName(
  42. HDEV hdev
  43. )
  44. {
  45. PUMPD pUMPD;
  46. if ((pUMPD = (PUMPD) NtGdiGetDhpdev(hdev)) == NULL)
  47. return NULL;
  48. if (pUMPD->dwSignature != UMPD_SIGNATURE)
  49. pUMPD = ((PUMDHPDEV) pUMPD)->pUMPD;
  50. return pUMPD->pDriverInfo2->pDriverPath;
  51. }
  52. PULONG APIENTRY XLATEOBJ_piVector(
  53. IN XLATEOBJ *pxlo
  54. )
  55. {
  56. return ((ULONG *)pxlo->pulXlate);
  57. }
  58. //
  59. // Simulate kernel-mode file mapping functions
  60. //
  61. HANDLE
  62. EngLoadModule(
  63. LPWSTR pwsz
  64. )
  65. {
  66. return LoadLibraryExW(pwsz, NULL, LOAD_LIBRARY_AS_DATAFILE);
  67. }
  68. PVOID
  69. EngFindResource(
  70. HANDLE h,
  71. INT iName,
  72. INT iType,
  73. PULONG pulSize
  74. )
  75. {
  76. HRSRC hrsrc;
  77. HGLOBAL hmem;
  78. PVOID p = NULL;
  79. DWORD size = 0;
  80. hrsrc = FindResourceW(h, MAKEINTRESOURCEW(iName), MAKEINTRESOURCEW(iType));
  81. if (hrsrc != NULL &&
  82. (size = SizeofResource(h, hrsrc)) != 0 &&
  83. (hmem = LoadResource(h, hrsrc)) != NULL)
  84. {
  85. p = LockResource(hmem);
  86. }
  87. *pulSize = size;
  88. return p;
  89. }
  90. VOID
  91. EngFreeModule(
  92. HANDLE h
  93. )
  94. {
  95. FreeLibrary(h);
  96. }
  97. //
  98. // Unicode <=> MultiByte conversion functions
  99. //
  100. VOID
  101. EngMultiByteToUnicodeN(
  102. PWSTR UnicodeString,
  103. ULONG MaxBytesInUnicodeString,
  104. PULONG BytesInUnicodeString,
  105. PCHAR MultiByteString,
  106. ULONG BytesInMultiByteString
  107. )
  108. {
  109. RtlMultiByteToUnicodeN(UnicodeString,
  110. MaxBytesInUnicodeString,
  111. BytesInUnicodeString,
  112. MultiByteString,
  113. BytesInMultiByteString);
  114. }
  115. VOID
  116. EngUnicodeToMultiByteN(
  117. PCHAR MultiByteString,
  118. ULONG MaxBytesInMultiByteString,
  119. PULONG BytesInMultiByteString,
  120. PWSTR UnicodeString,
  121. ULONG BytesInUnicodeString
  122. )
  123. {
  124. RtlUnicodeToMultiByteN(MultiByteString,
  125. MaxBytesInMultiByteString,
  126. BytesInMultiByteString,
  127. UnicodeString,
  128. BytesInUnicodeString);
  129. }
  130. INT
  131. EngMultiByteToWideChar(
  132. UINT CodePage,
  133. LPWSTR WideCharString,
  134. INT BytesInWideCharString,
  135. LPSTR MultiByteString,
  136. INT BytesInMultiByteString
  137. )
  138. {
  139. return MultiByteToWideChar(CodePage,
  140. 0,
  141. MultiByteString,
  142. BytesInMultiByteString,
  143. WideCharString,
  144. BytesInWideCharString / sizeof(WCHAR));
  145. }
  146. INT
  147. EngWideCharToMultiByte(
  148. UINT CodePage,
  149. LPWSTR WideCharString,
  150. INT BytesInWideCharString,
  151. LPSTR MultiByteString,
  152. INT BytesInMultiByteString
  153. )
  154. {
  155. return WideCharToMultiByte(CodePage,
  156. 0,
  157. WideCharString,
  158. BytesInWideCharString / sizeof(WCHAR),
  159. MultiByteString,
  160. BytesInMultiByteString,
  161. NULL,
  162. NULL);
  163. }
  164. VOID
  165. EngGetCurrentCodePage(
  166. PUSHORT OemCodePage,
  167. PUSHORT AnsiCodePage
  168. )
  169. {
  170. *AnsiCodePage = (USHORT) GetACP();
  171. *OemCodePage = (USHORT) GetOEMCP();
  172. }
  173. //
  174. // Copy FD_GLYPHSET information
  175. //
  176. // IMPORTANT!!
  177. // We assume FD_GLYPHSET information is stored in one contiguous block
  178. // of memory and FD_GLYPHSET.cjThis field is the size of the entire block.
  179. // HGLYPH arrays in each WCRUN are part of the block, placed just after
  180. // FD_GLYPHSET structure itself.
  181. //
  182. BOOL
  183. CopyFD_GLYPHSET(
  184. FD_GLYPHSET *dst,
  185. FD_GLYPHSET *src,
  186. ULONG cjSize
  187. )
  188. {
  189. ULONG index, offset;
  190. RtlCopyMemory(dst, src, cjSize);
  191. //
  192. // Patch up memory pointers in each WCRUN structure
  193. //
  194. for (index=0; index < src->cRuns; index++)
  195. {
  196. if (src->awcrun[index].phg != NULL)
  197. {
  198. offset = (ULONG) ((PBYTE) src->awcrun[index].phg - (PBYTE) src);
  199. if (offset >= cjSize)
  200. {
  201. WARNING("GreCopyFD_GLYPHSET failed.\n");
  202. return FALSE;
  203. }
  204. dst->awcrun[index].phg = (HGLYPH*) ((PBYTE) dst + offset);
  205. }
  206. }
  207. return TRUE;
  208. }
  209. FD_GLYPHSET*
  210. EngComputeGlyphSet(
  211. INT nCodePage,
  212. INT nFirstChar,
  213. INT cChars
  214. )
  215. {
  216. FD_GLYPHSET *pGlyphSet, *pGlyphSetTmp = NULL;
  217. ULONG cjSize;
  218. //
  219. // The driver will always call EngFreeMem after done using pGlyphSet
  220. // We have to provide them a user mode pointer here
  221. //
  222. if ((pGlyphSet = NtGdiEngComputeGlyphSet(nCodePage, nFirstChar, cChars)) &&
  223. (cjSize = pGlyphSet->cjThis) &&
  224. (pGlyphSetTmp = (FD_GLYPHSET *) GlobalAlloc(GMEM_FIXED, cjSize)))
  225. {
  226. if (!CopyFD_GLYPHSET(pGlyphSetTmp, pGlyphSet, cjSize))
  227. {
  228. GlobalFree((HGLOBAL) pGlyphSetTmp);
  229. pGlyphSetTmp = NULL;
  230. }
  231. }
  232. //
  233. // the user memory allocated from the kernel (pGlyphSet)
  234. // will be gone after the call is finished
  235. //
  236. return (pGlyphSetTmp);
  237. }
  238. //
  239. // Query current local time
  240. //
  241. VOID
  242. EngQueryLocalTime(
  243. PENG_TIME_FIELDS ptf
  244. )
  245. {
  246. SYSTEMTIME localtime;
  247. GetLocalTime(&localtime);
  248. ptf->usYear = localtime.wYear;
  249. ptf->usMonth = localtime.wMonth;
  250. ptf->usDay = localtime.wDay;
  251. ptf->usHour = localtime.wHour;
  252. ptf->usMinute = localtime.wMinute;
  253. ptf->usSecond = localtime.wSecond;
  254. ptf->usMilliseconds = localtime.wMilliseconds;
  255. ptf->usWeekday = localtime.wDayOfWeek;
  256. }
  257. //
  258. // Simulate Eng-semaphore functions
  259. //
  260. HSEMAPHORE
  261. EngCreateSemaphore(
  262. VOID
  263. )
  264. {
  265. LPCRITICAL_SECTION pcs;
  266. if (pcs = (LPCRITICAL_SECTION) LOCALALLOC(sizeof(CRITICAL_SECTION)))
  267. {
  268. InitializeCriticalSection(pcs);
  269. }
  270. else
  271. {
  272. WARNING("Memory allocation failed.\n");
  273. }
  274. return (HSEMAPHORE) pcs;
  275. }
  276. VOID
  277. EngAcquireSemaphore(
  278. HSEMAPHORE hsem
  279. )
  280. {
  281. EnterCriticalSection((LPCRITICAL_SECTION) hsem);
  282. }
  283. VOID
  284. EngReleaseSemaphore(
  285. HSEMAPHORE hsem
  286. )
  287. {
  288. LeaveCriticalSection((LPCRITICAL_SECTION) hsem);
  289. }
  290. VOID
  291. EngDeleteSemaphore(
  292. HSEMAPHORE hsem
  293. )
  294. {
  295. LPCRITICAL_SECTION pcs = (LPCRITICAL_SECTION) hsem;
  296. if (pcs != NULL)
  297. {
  298. DeleteCriticalSection(pcs);
  299. LOCALFREE(pcs);
  300. }
  301. }
  302. BOOL APIENTRY
  303. EngQueryEMFInfo(
  304. HDEV hdev,
  305. EMFINFO *pEMFInfo)
  306. {
  307. WARNING("EngQueryEMFInfo no longer supported\n");
  308. return FALSE;
  309. }
  310. #endif // !_GDIPLUS_
  311.