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.

194 lines
4.9 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. FreeSplMem(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 dwRet = ERROR_SUCCESS;
  61. PCWSTR pOut = NULL;
  62. //
  63. // The returned xcv name can be of two basic forms. The first
  64. // form is were the server name is non null and the other is
  65. // if the server name is null or a null string.
  66. //
  67. // Example 1
  68. //
  69. // pServerName = NULL;
  70. // pObjectName = IP_1.2.3.4
  71. // pObjectType = XcvPort
  72. //
  73. // Returned String
  74. //
  75. // ,XcvPort IP_1.2.3.4
  76. //
  77. // Example 2
  78. //
  79. // pServerName = \\Server1
  80. // pObjectName = IP_1.2.3.4
  81. // pObjectType = XcvPort
  82. //
  83. // Returned String
  84. //
  85. // \\Server1\,XcvPort IP_1.2.3.4
  86. //
  87. dwRet = StrCatAlloc(&pOut,
  88. (pServerName && *pServerName) ? pServerName : L"",
  89. (pServerName && *pServerName) ? L"\\" : L"",
  90. L",",
  91. pObjectType,
  92. L" ",
  93. pObjectName,
  94. NULL);
  95. //
  96. // Use the return value not the out pointer.
  97. //
  98. return dwRet == ERROR_SUCCESS ? (PWSTR)pOut : NULL;
  99. }
  100. VOID
  101. TXcvDlg::DisplayLastError (
  102. HWND hWnd,
  103. UINT iTitle)
  104. {
  105. DisplayErrorMsg (m_hInst, hWnd, iTitle, GetLastError ());
  106. }
  107. VOID
  108. TXcvDlg::DisplayErrorMsg (
  109. HINSTANCE hInst,
  110. HWND hWnd,
  111. UINT iTitle,
  112. DWORD dwLE)
  113. {
  114. TCHAR szBuf[MAX_BUF_SIZE];
  115. TCHAR szMsgBuf[MAX_BUF_SIZE];
  116. UINT iMsg;
  117. LPTSTR lpMsgBuf = NULL;
  118. BOOL bFound = TRUE;
  119. switch (dwLE) {
  120. case ERROR_ACCESS_DENIED:
  121. iMsg = IDS_ACCESS_DENIED;
  122. break;
  123. case ERROR_INVALID_NAME:
  124. case ERROR_INVALID_PRINTER_NAME:
  125. iMsg = IDS_INVALID_PRINTER_NAME;
  126. break;
  127. case ERROR_INTERNET_TIMEOUT:
  128. iMsg = IDS_NETWORK_TIMEOUT;
  129. break;
  130. case ERROR_DEVICE_REINITIALIZATION_NEEDED:
  131. iMsg = IDS_INITIALIZATION_ERROR;
  132. break;
  133. case ERROR_NOT_FOUND:
  134. iMsg = IDS_PORT_DELETED;
  135. break;
  136. default:
  137. bFound = FALSE;
  138. break;
  139. }
  140. if (LoadString (hInst, iTitle, szBuf, MAX_BUF_SIZE)) {
  141. if (bFound) {
  142. if (LoadString (hInst, iMsg, szMsgBuf, MAX_BUF_SIZE))
  143. MessageBox( hWnd, szMsgBuf, szBuf, MB_OK | MB_ICONERROR);
  144. }
  145. else {
  146. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  147. FORMAT_MESSAGE_FROM_SYSTEM |
  148. FORMAT_MESSAGE_IGNORE_INSERTS,
  149. NULL,
  150. GetLastError(),
  151. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  152. (LPTSTR) &lpMsgBuf,
  153. 0,
  154. NULL) && lpMsgBuf) {
  155. MessageBox( hWnd, (LPCTSTR)lpMsgBuf, szBuf, MB_OK | MB_ICONERROR );
  156. // Free the buffer.
  157. LocalFree( lpMsgBuf );
  158. }
  159. else {
  160. //
  161. // Most likely it is because we've got an error code from wininet, where
  162. // we can not locate the resource file
  163. //
  164. if (LoadString (hInst, IDS_INVALID_SETTING, szMsgBuf, MAX_BUF_SIZE))
  165. MessageBox( hWnd, szMsgBuf, szBuf, MB_OK | MB_ICONERROR);
  166. }
  167. }
  168. }
  169. }