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.

179 lines
4.4 KiB

  1. /*****************************************************************************\
  2. * MODULE: configdlg.cxx
  3. *
  4. * The module contains routines for handling the authentication dialog
  5. * for internet priting
  6. *
  7. * Copyright (C) 1996-1998 Microsoft Corporation
  8. *
  9. * History:
  10. * 07/31/98 WeihaiC Created
  11. * 04/10/00 WeihaiC Moved it to client side
  12. *
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #include "priv.h"
  16. TXcvDlg::TXcvDlg (
  17. LPCWSTR pServerName,
  18. HWND hWnd,
  19. LPCWSTR pszPortName):
  20. m_pServerName (pServerName),
  21. m_hWnd (hWnd),
  22. m_pszPortName (pszPortName),
  23. m_pXcvName (NULL),
  24. m_hXcvPort (NULL),
  25. m_bAdmin (FALSE),
  26. m_hInst (NULL),
  27. m_dwLE (ERROR_SUCCESS),
  28. m_bValid (FALSE)
  29. {
  30. DWORD cbNeeded, dwStatus;
  31. PRINTER_DEFAULTS pd = {NULL, NULL, SERVER_ALL_ACCESS};
  32. HANDLE hServer;
  33. BOOL bRet = FALSE;
  34. if (OpenPrinter (NULL, &hServer, &pd)) {
  35. ClosePrinter (hServer);
  36. m_bAdmin = TRUE;
  37. }
  38. if (m_pXcvName = ConstructXcvName (m_pServerName, m_pszPortName, L"XcvPort")) {
  39. if (OpenPrinter (m_pXcvName, &m_hXcvPort, NULL)) {
  40. m_bValid = TRUE;
  41. }
  42. }
  43. }
  44. TXcvDlg::~TXcvDlg ()
  45. {
  46. if (m_pXcvName) {
  47. LocalFree (m_pXcvName);
  48. }
  49. if (m_hXcvPort) {
  50. ClosePrinter (m_hXcvPort);
  51. }
  52. }
  53. PWSTR
  54. TXcvDlg::ConstructXcvName(
  55. PCWSTR pServerName,
  56. PCWSTR pObjectName,
  57. PCWSTR pObjectType
  58. )
  59. {
  60. DWORD cbOutput;
  61. PWSTR pOut;
  62. cbOutput = pServerName ? (wcslen(pServerName) + 2)*sizeof(WCHAR) : sizeof(WCHAR); /* "\\Server\," */
  63. cbOutput += (wcslen(pObjectType) + 2)*sizeof(WCHAR); /* "\\Server\,XcvPort _" */
  64. cbOutput += pObjectName ? (wcslen(pObjectName))*sizeof(WCHAR) : 0; /* "\\Server\,XcvPort Object_" */
  65. //
  66. // For some reason, new crashes explorer, so we use LocalAlloc instead - weihaic
  67. //
  68. if (pOut = (PWSTR) LocalAlloc (LPTR, sizeof (WCHAR) * cbOutput)) { //new WCHAR [cbOutput]) {
  69. if (pServerName) {
  70. wcscpy(pOut,pServerName);
  71. wcscat(pOut, L"\\");
  72. }
  73. wcscat(pOut,L",");
  74. wcscat(pOut,pObjectType);
  75. wcscat(pOut,L" ");
  76. if (pObjectName)
  77. wcscat(pOut,pObjectName);
  78. }
  79. return pOut;
  80. }
  81. VOID
  82. TXcvDlg::DisplayLastError (
  83. HWND hWnd,
  84. UINT iTitle)
  85. {
  86. DisplayErrorMsg (m_hInst, hWnd, iTitle, GetLastError ());
  87. }
  88. VOID
  89. TXcvDlg::DisplayErrorMsg (
  90. HINSTANCE hInst,
  91. HWND hWnd,
  92. UINT iTitle,
  93. DWORD dwLE)
  94. {
  95. TCHAR szBuf[MAX_BUF_SIZE];
  96. TCHAR szMsgBuf[MAX_BUF_SIZE];
  97. UINT iMsg;
  98. LPTSTR lpMsgBuf = NULL;
  99. BOOL bFound = TRUE;
  100. switch (dwLE) {
  101. case ERROR_ACCESS_DENIED:
  102. iMsg = IDS_ACCESS_DENIED;
  103. break;
  104. case ERROR_INVALID_NAME:
  105. case ERROR_INVALID_PRINTER_NAME:
  106. iMsg = IDS_INVALID_PRINTER_NAME;
  107. break;
  108. case ERROR_INTERNET_TIMEOUT:
  109. iMsg = IDS_NETWORK_TIMEOUT;
  110. break;
  111. case ERROR_DEVICE_REINITIALIZATION_NEEDED:
  112. iMsg = IDS_INITIALIZATION_ERROR;
  113. break;
  114. case ERROR_NOT_FOUND:
  115. iMsg = IDS_PORT_DELETED;
  116. break;
  117. default:
  118. bFound = FALSE;
  119. break;
  120. }
  121. if (LoadString (hInst, iTitle, szBuf, MAX_BUF_SIZE)) {
  122. if (bFound) {
  123. if (LoadString (hInst, iMsg, szMsgBuf, MAX_BUF_SIZE))
  124. MessageBox( hWnd, szMsgBuf, szBuf, MB_OK | MB_ICONERROR);
  125. }
  126. else {
  127. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  128. FORMAT_MESSAGE_FROM_SYSTEM |
  129. FORMAT_MESSAGE_IGNORE_INSERTS,
  130. NULL,
  131. GetLastError(),
  132. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  133. (LPTSTR) &lpMsgBuf,
  134. 0,
  135. NULL) && lpMsgBuf) {
  136. MessageBox( hWnd, (LPCTSTR)lpMsgBuf, szBuf, MB_OK | MB_ICONERROR );
  137. // Free the buffer.
  138. LocalFree( lpMsgBuf );
  139. }
  140. else {
  141. //
  142. // Most likely it is because we've got an error code from wininet, where
  143. // we can not locate the resource file
  144. //
  145. if (LoadString (hInst, IDS_INVALID_SETTING, szMsgBuf, MAX_BUF_SIZE))
  146. MessageBox( hWnd, szMsgBuf, szBuf, MB_OK | MB_ICONERROR);
  147. }
  148. }
  149. }
  150. }