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.

324 lines
12 KiB

  1. //**************************************************************************
  2. // WOW fax support:
  3. // supports delrina winfax only
  4. // - nandurir created
  5. //**************************************************************************
  6. #define NOGDI
  7. #define PRINTDRIVER
  8. #define _WOWFAX16_
  9. #define DEFINE_DDRV_DEBUG_STRINGS
  10. #include "wowexec.h"
  11. #include "wowfax.h"
  12. #define WOWDRV_BITBLT MAKEINTRESOURCE(1)
  13. #define WOWDRV_CONTROL MAKEINTRESOURCE(3)
  14. #define WOWDRV_DISABLE MAKEINTRESOURCE(4)
  15. #define WOWDRV_ENABLE MAKEINTRESOURCE(5)
  16. #define WOWDRV_EXTDEVMODE MAKEINTRESOURCE(90)
  17. #define WOWDRV_DEVCAPS MAKEINTRESOURCE(91)
  18. //**************************************************************************
  19. // FaxWndProc
  20. //
  21. // NOTE: the definitions such as 'BITMAP' struct is different in this
  22. // file. This file is compiled with NOGDI option so that the
  23. // printer driver versions of the structure get defined
  24. // (in gdidefs.inc). However we donot use printer drivers version
  25. // of such structures, particularly BITMAP.
  26. //**************************************************************************
  27. LONG FAR PASCAL FaxWndProc(HWND hwnd, WORD message, WORD hdc,
  28. LPWOWFAXINFO16 lpfaxinfo)
  29. {
  30. LPPOINT lppt;
  31. HANDLE hMem;
  32. RECT rc;
  33. HINSTANCE hInst;
  34. WORD wSize;
  35. LONG lRet = (LONG)lpfaxinfo;
  36. WORD wRet;
  37. char szDriverFileName[MAXITEMPATHLEN+1];
  38. #ifdef DEBUG
  39. char szTmp[128];
  40. if ((message >= WM_DDRV_FIRST) && (message <= WM_DDRV_LAST)) {
  41. wsprintf(szTmp, "FaxWndProc, 0x%XH, %s, 0x%XH, 0x%lX\n", hwnd, (LPSTR) szWmDdrvDebugStrings[message - WM_DDRV_FIRST], hdc, lpfaxinfo);
  42. OutputDebugString((LPSTR) szTmp);
  43. }
  44. #endif
  45. switch (message) {
  46. default:
  47. return DefWindowProc(hwnd, message, hdc, (LPARAM)lpfaxinfo);
  48. break;
  49. case WM_DDRV_INITFAXINFO16:
  50. // allocate and initialize lpfaxinfo
  51. hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
  52. sizeof(WOWFAXINFO16));
  53. lpfaxinfo = (LPWOWFAXINFO16)GlobalLock(hMem);
  54. if (lpfaxinfo) {
  55. lpfaxinfo->hmem = hMem;
  56. }
  57. lRet = (LONG)lpfaxinfo;
  58. break;
  59. case WM_DDRV_ENABLE:
  60. case WM_DDRV_LOAD:
  61. // now load the drv - lpfaxinfo must have been initialized
  62. if (lpfaxinfo == (LPWOWFAXINFO16)NULL)
  63. break;
  64. lstrcpy(szDriverFileName, lpfaxinfo->lpDriverName);
  65. lstrcat(szDriverFileName, ".DRV");
  66. hInst = lpfaxinfo->hInst = LoadLibrary(szDriverFileName);
  67. if (hInst) {
  68. // store necessary info
  69. (FARPROC)lpfaxinfo->lpControl = GetProcAddress(hInst, WOWDRV_CONTROL);
  70. (FARPROC)lpfaxinfo->lpDisable = GetProcAddress(hInst, WOWDRV_DISABLE);
  71. (FARPROC)lpfaxinfo->lpEnable = GetProcAddress(hInst, WOWDRV_ENABLE);
  72. (FARPROC)lpfaxinfo->lpBitblt = GetProcAddress(hInst, WOWDRV_BITBLT);
  73. (FARPROC)lpfaxinfo->lpExtDMode = GetProcAddress(hInst, WOWDRV_EXTDEVMODE);
  74. (FARPROC)lpfaxinfo->lpDevCaps = GetProcAddress(hInst, WOWDRV_DEVCAPS);
  75. if (!lpfaxinfo->lpControl || !lpfaxinfo->lpDisable || !lpfaxinfo->lpEnable ||
  76. !lpfaxinfo->lpBitblt || !lpfaxinfo->lpExtDMode || !lpfaxinfo->lpDevCaps) {
  77. #ifdef DEBUG
  78. wsprintf(szTmp, "FaxWndProc, Failed GetProcAddress on: %s\n", szDriverFileName);
  79. OutputDebugString((LPSTR) szTmp);
  80. #endif
  81. lRet = 0;
  82. }
  83. }
  84. else {
  85. #ifdef DEBUG
  86. wsprintf(szTmp, "FaxWndProc, Failed load of: %s\n", szDriverFileName);
  87. OutputDebugString((LPSTR) szTmp);
  88. #endif
  89. lRet = 0;
  90. }
  91. if (message == WM_DDRV_LOAD || lRet == 0)
  92. break;
  93. // case WM_DDRV_ENABLE continues
  94. if (lpfaxinfo) {
  95. // win31 gdi calls 'enable' twice - first to get the gdiinfo struct and next to get
  96. // pdevice struct
  97. wRet = (*lpfaxinfo->lpEnable)(lpfaxinfo->lpOut, InquireInfo,
  98. lpfaxinfo->szDeviceName, lpfaxinfo->lpPortName, lpfaxinfo->lpIn);
  99. #ifdef DEBUG
  100. if (!wRet) {
  101. wsprintf(szTmp, "FaxWndProc, Enable InquireInfo Failed: %s, %s\n", szDriverFileName, lpfaxinfo->lpPortName);
  102. OutputDebugString((LPSTR) szTmp);
  103. }
  104. #endif
  105. hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
  106. ((LPGDIINFO)lpfaxinfo->lpOut)->dpDEVICEsize);
  107. lpfaxinfo->hmemdevice = hMem;
  108. lpfaxinfo->lpDevice = GlobalLock(hMem);
  109. if (!lpfaxinfo->lpDevice) {
  110. #ifdef DEBUG
  111. wsprintf(szTmp, "FaxWndProc, GlobalAlloc Failed: 0x%lX\n", ((LPGDIINFO)lpfaxinfo->lpOut)->dpDEVICEsize);
  112. OutputDebugString((LPSTR) szTmp);
  113. #endif
  114. return(0);
  115. }
  116. wRet = (*lpfaxinfo->lpEnable)(lpfaxinfo->lpDevice, EnableDevice,
  117. lpfaxinfo->szDeviceName, lpfaxinfo->lpPortName, lpfaxinfo->lpIn);
  118. #ifdef DEBUG
  119. if (!wRet) {
  120. wsprintf(szTmp, "FaxWndProc, Enable, EnableDevice Failed: %s, %s\n", szDriverFileName, lpfaxinfo->lpPortName);
  121. OutputDebugString((LPSTR) szTmp);
  122. }
  123. #endif
  124. lppt = (LPPOINT)((LPSTR)lpfaxinfo->lpOut + sizeof(GDIINFO16));
  125. lppt->x = lppt->y = 0;
  126. wRet = (*lpfaxinfo->lpControl)(lpfaxinfo->lpDevice, GETPRINTINGOFFSET, 0, lppt);
  127. #ifdef DEBUG
  128. if (!wRet) {
  129. OutputDebugString((LPSTR) "FaxWndProc, Control GETPRINTINGOFFSET Failed\n");
  130. }
  131. #endif
  132. lpfaxinfo->flState |= WFINFO16_ENABLED;
  133. }
  134. break;
  135. case WM_DDRV_STARTDOC:
  136. if (lpfaxinfo) {
  137. lRet = (LONG)(*lpfaxinfo->lpControl)(lpfaxinfo->lpDevice,
  138. SETPRINTERDC, (LPSTR)&hdc, 0);
  139. if (lRet) {
  140. // EasyFax Ver2.0 support
  141. // Also Procomm+ 3 cover sheets. Bug #305665
  142. lRet = (LONG)(*lpfaxinfo->lpControl)(lpfaxinfo->lpDevice,
  143. STARTDOC, (LPSTR)lpfaxinfo->szDocName, 0);
  144. #ifdef DEBUG
  145. if (lRet < 0) {
  146. OutputDebugString((LPSTR) "FaxWndProc, Control STARTDOC Failed\n");
  147. }
  148. #endif
  149. }
  150. #ifdef DEBUG
  151. else {
  152. OutputDebugString((LPSTR) "FaxWndProc, Control SETPRINTERDC Failed\n");
  153. }
  154. #endif
  155. }
  156. break;
  157. case WM_DDRV_PRINTPAGE:
  158. if (lpfaxinfo) {
  159. for (;;) {
  160. lRet = (LONG)(*lpfaxinfo->lpControl)(lpfaxinfo->lpDevice,
  161. NEXTBAND, NULL, (LPSTR)&rc);
  162. if (lRet < 0) {
  163. #ifdef DEBUG
  164. OutputDebugString((LPSTR) "FaxWndProc, Control NEXTBAND Failed\n");
  165. #endif
  166. break;
  167. }
  168. if (rc.left || rc.top || rc.right || rc.bottom) {
  169. wRet = (*lpfaxinfo->lpBitblt)(lpfaxinfo->lpDevice, rc.left, rc.top,
  170. NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
  171. SRCCOPY, NULL, NULL);
  172. #ifdef DEBUG
  173. if (!wRet) {
  174. OutputDebugString((LPSTR) "FaxWndProc, BitBlt Failed\n");
  175. }
  176. #endif
  177. }
  178. else {
  179. break;
  180. }
  181. }
  182. }
  183. break;
  184. case WM_DDRV_ENDDOC:
  185. if (lpfaxinfo) {
  186. lRet = (LONG)(*lpfaxinfo->lpControl)(lpfaxinfo->lpDevice, ENDDOC, 0, 0);
  187. #ifdef DEBUG
  188. if (lRet <= 0) {
  189. OutputDebugString((LPSTR) "FaxWndProc, Control ENDDOC Failed\n");
  190. }
  191. #endif
  192. }
  193. break;
  194. case WM_DDRV_ESCAPE:
  195. if (lpfaxinfo) {
  196. lRet = (LONG)(*lpfaxinfo->lpControl)(lpfaxinfo->lpDevice, lpfaxinfo->wCmd, 0, 0);
  197. #ifdef DEBUG
  198. if (lRet <= 0) {
  199. wsprintf(szTmp, "FaxWndProc, Escape %X Failed\n", lpfaxinfo->wCmd);
  200. OutputDebugString((LPSTR) szTmp);
  201. }
  202. #endif
  203. }
  204. break;
  205. case WM_DDRV_DISABLE:
  206. if (lpfaxinfo) {
  207. if (lpfaxinfo->flState & WFINFO16_ENABLED) {
  208. (*lpfaxinfo->lpDisable)(lpfaxinfo->lpDevice);
  209. }
  210. GlobalUnlock(lpfaxinfo->hmemdevice);
  211. GlobalFree(lpfaxinfo->hmemdevice);
  212. }
  213. lRet = 0;
  214. // fall through
  215. case WM_DDRV_UNLOAD:
  216. if (lpfaxinfo) {
  217. if (lpfaxinfo->hInst) {
  218. FreeLibrary(lpfaxinfo->hInst);
  219. }
  220. }
  221. lRet = 0;
  222. // fall through
  223. case WM_DDRV_FREEFAXINFO16:
  224. if (lpfaxinfo) {
  225. GlobalUnlock(lpfaxinfo->hmem);
  226. GlobalFree(lpfaxinfo->hmem);
  227. lpfaxinfo = (LPWOWFAXINFO16)NULL;
  228. }
  229. lRet = 0;
  230. break;
  231. case WM_DDRV_EXTDMODE:
  232. if (lpfaxinfo) {
  233. lRet = (*lpfaxinfo->lpExtDMode)(lpfaxinfo->hwndui, lpfaxinfo->hInst,
  234. lpfaxinfo->lpOut, lpfaxinfo->szDeviceName, lpfaxinfo->lpPortName,
  235. lpfaxinfo->lpIn, 0, lpfaxinfo->wCmd);
  236. }
  237. break;
  238. case WM_DDRV_DEVCAPS:
  239. if (lpfaxinfo) {
  240. lRet = (*lpfaxinfo->lpDevCaps)(lpfaxinfo->szDeviceName, lpfaxinfo->lpPortName,
  241. lpfaxinfo->wCmd, lpfaxinfo->lpOut, 0);
  242. }
  243. break;
  244. }
  245. return lRet;
  246. }
  247. //**************************************************************************
  248. // FaxInit
  249. //
  250. //**************************************************************************
  251. HWND FaxInit(HINSTANCE hInst)
  252. {
  253. WNDCLASS wc;
  254. // Make sure we only allow one FaxWndProc to handle WowFax messages
  255. if (FindWindow(WOWFAX_CLASS, NULL)) {
  256. return((HWND)0);
  257. }
  258. wc.style = 0;
  259. wc.lpfnWndProc = (WNDPROC)FaxWndProc;
  260. wc.cbClsExtra = 0;
  261. wc.cbWndExtra = 0;
  262. wc.hInstance = hInst;
  263. wc.hIcon = 0;
  264. wc.hCursor = 0;
  265. wc.hbrBackground = 0;
  266. wc.lpszMenuName = 0;
  267. wc.lpszClassName = WOWFAX_CLASS;
  268. if (!RegisterClass(&wc)) {
  269. return (HWND)0;
  270. }
  271. return CreateWindow(wc.lpszClassName, "", WS_OVERLAPPEDWINDOW,
  272. 0, 0, 0, 0, NULL, NULL, hInst, NULL);
  273. }