Source code of Windows XP (NT5)
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.

249 lines
5.8 KiB

  1. /*****************************************************************************\
  2. * MODULE: wpnpin32.cxx
  3. *
  4. * Entry/Exit routines for the library.
  5. *
  6. * Routines
  7. * --------
  8. * PrintUIEntryW
  9. * PrintUIEntryA
  10. *
  11. *
  12. * Copyright (C) 1997-1998 Hewlett-Packard Company.
  13. * Copyright (C) 1997-1998 Microsoft Corporation.
  14. *
  15. * History:
  16. * 10-Oct-1997 GFS Initial checkin
  17. * 23-Oct-1997 GFS Modified PrintUIEntry to PrintUIEntryW
  18. * 22-Jun-1998 CHW Cleaned
  19. *
  20. \*****************************************************************************/
  21. #include "libpriv.h"
  22. /*****************************************************************************\
  23. * PrintUIEntryW (Unicode)
  24. *
  25. *
  26. \*****************************************************************************/
  27. DLLEXPORT DWORD WINAPI PrintUIEntryW(
  28. HWND hWnd,
  29. HINSTANCE hInstance,
  30. LPCWSTR lpwszCmdDat,
  31. int nShow)
  32. {
  33. DWORD dwRet;
  34. int cbSize = 0;
  35. LPSTR lpszCmdDat = NULL;
  36. cbSize = WideCharToMultiByte(CP_ACP,
  37. 0,
  38. lpwszCmdDat,
  39. -1,
  40. lpszCmdDat,
  41. cbSize,
  42. NULL,
  43. NULL);
  44. if (lpszCmdDat = (LPSTR)memAlloc(cbSize)) {
  45. if (WideCharToMultiByte(CP_ACP,
  46. 0,
  47. lpwszCmdDat,
  48. -1,
  49. lpszCmdDat,
  50. cbSize,
  51. NULL,
  52. NULL)) {
  53. dwRet = PrintUIEntryA(hWnd, hInstance, lpszCmdDat, nShow);
  54. } else {
  55. dwRet = E_FAIL;
  56. }
  57. memFree(lpszCmdDat, cbSize);
  58. } else {
  59. dwRet = ERROR_OUTOFMEMORY;
  60. }
  61. // Set lasterror and return error.
  62. //
  63. SetLastError(dwRet);
  64. return dwRet;
  65. }
  66. /*****************************************************************************\
  67. * PrintUIEntryA (Ansi)
  68. *
  69. *
  70. \*****************************************************************************/
  71. DLLEXPORT DWORD WINAPI PrintUIEntryA(
  72. HWND hWnd,
  73. HINSTANCE hInstance,
  74. LPCSTR lpszCmdDat,
  75. int nShow)
  76. {
  77. DWORD dwResult;
  78. UINT idTxt;
  79. UINT fMB;
  80. int nArgs;
  81. DWORD dwRet;
  82. LPSI lpsi;
  83. TCHAR *pszCap = NULL;
  84. INT cbStrLength = 0;
  85. // lop off the offending '@' at beginning of name.
  86. //
  87. lpszCmdDat++;
  88. // Create a SETUPINFO structure and proceed to the
  89. // installation.
  90. //
  91. if (lpsi = (LPSI)memAlloc(sizeof(SETUPINFO))) {
  92. // Parse command-line args into the (lpsi) structure. The
  93. // return of this function will return the number of arguments
  94. // encountered.
  95. //
  96. nArgs = GetCommandLineArgs(lpsi, lpszCmdDat);
  97. // Add the printer. This launches the whole process.
  98. //
  99. dwResult = (nArgs == 8 ? AddOnePrinter(lpsi, hWnd) : RET_INVALID_DAT_FILE);
  100. cbStrLength = lstrlen( lpsi->szFriendly ) + 1;
  101. pszCap = (TCHAR *)memAlloc( cbStrLength * sizeof(TCHAR) );
  102. if (pszCap)
  103. {
  104. if (cbStrLength > 1)
  105. {
  106. // Put the friendly-name as our caption.
  107. //
  108. lstrcpy( pszCap, lpsi->szFriendly );
  109. *(pszCap + lstrlen(pszCap) * sizeof(TCHAR)) = TEXT('\0');
  110. }
  111. else
  112. {
  113. *pszCap = TEXT('\0');
  114. }
  115. }
  116. // Clean up memory not cleaned up in AddPrinter
  117. //
  118. memFree(lpsi, sizeof(SETUPINFO));
  119. lpsi = NULL;
  120. } else {
  121. if (g_szPrinter)
  122. {
  123. cbStrLength = lstrlen(g_szPrinter);
  124. }
  125. cbStrLength += 1;
  126. pszCap = memAlloc(cbStrLength * sizeof(TCHAR));
  127. if (pszCap)
  128. {
  129. if (cbStrLength > 1)
  130. {
  131. lstrcpy(pszCap, g_szPrinter);
  132. }
  133. else
  134. {
  135. *pszCap = TEXT('\0');
  136. }
  137. }
  138. dwResult = RET_ALLOC_ERR;
  139. }
  140. // This what we'll return to the caller.
  141. //
  142. dwRet = (dwResult == RET_OK ? ERROR_SUCCESS : E_FAIL);
  143. // Give the caller a message indicating the status of the
  144. // printer install.
  145. //
  146. switch (dwResult) {
  147. case RET_OK:
  148. idTxt = IDS_OK;
  149. fMB = MB_OK | MB_ICONASTERISK;
  150. break;
  151. case RET_ALLOC_ERR:
  152. case RET_DRIVER_NODE_ERROR:
  153. idTxt = IDS_ALLOC_ERR;
  154. fMB = MB_OK | MB_ICONEXCLAMATION;
  155. break;
  156. case RET_INVALID_INFFILE:
  157. case RET_SECT_NOT_FOUND:
  158. case RET_INVALID_PRINTER_DRIVER:
  159. case RET_INVALID_DLL:
  160. case RET_DRIVER_NOT_FOUND:
  161. case RET_DRIVER_FOUND:
  162. idTxt = IDS_INVALID_INFFILE;
  163. fMB = MB_OK | MB_ICONEXCLAMATION;
  164. break;
  165. case RET_NO_UNIQUE_NAME:
  166. idTxt = IDS_NO_UNIQUE_NAME;
  167. fMB = MB_OK | MB_ICONSTOP;
  168. break;
  169. case RET_USER_CANCEL:
  170. idTxt = IDS_USER_CANCEL;
  171. fMB = MB_OK | MB_ICONEXCLAMATION;
  172. break;
  173. case RET_FILE_COPY_ERROR:
  174. idTxt = IDS_FILE_COPY_ERROR;
  175. fMB = MB_OK | MB_ICONHAND;
  176. break;
  177. case RET_ADD_PRINTER_ERROR:
  178. idTxt = IDS_ADD_PRINTER_ERROR;
  179. fMB = MB_OK | MB_ICONERROR;
  180. break;
  181. case RET_BROWSE_ERROR:
  182. idTxt = IDS_BROWSE_ERR;
  183. fMB = MB_OK | MB_ICONERROR;
  184. break;
  185. case RET_INVALID_DAT_FILE:
  186. idTxt = IDS_INVALID_DAT_FILE;
  187. fMB = MB_OK | MB_ICONERROR;
  188. break;
  189. default:
  190. idTxt = IDS_DEFAULT_ERROR;
  191. fMB = MB_OK | MB_ICONERROR;
  192. break;
  193. }
  194. // Display the messagebox.
  195. //
  196. prvMsgBox(hWnd, szCap, idTxt, fMB);
  197. if (pszCap)
  198. {
  199. memFree( pszCap, cbStrLength * sizeof(TCHAR) );
  200. }
  201. return dwRet;
  202. }