ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

localui.c
Go to the documentation of this file.
00001 /*
00002  * Implementation of the Local Printmonitor User Interface
00003  *
00004  * Copyright 2007 Detlef Riekenberg
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <stdarg.h>
00022 
00023 #define NONAMELESSUNION
00024 
00025 #include "windef.h"
00026 #include "winbase.h"
00027 #include "wingdi.h"
00028 #include "winreg.h"
00029 #include "winuser.h"
00030 
00031 #include "winspool.h"
00032 #include "ddk/winsplp.h"
00033 
00034 #include "wine/debug.h"
00035 #include "wine/unicode.h"
00036 #include "localui.h"
00037 
00038 WINE_DEFAULT_DEBUG_CHANNEL(localui);
00039 
00040 /*****************************************************/
00041 
00042 static HINSTANCE LOCALUI_hInstance;
00043 
00044 static const WCHAR cmd_AddPortW[] = {'A','d','d','P','o','r','t',0};
00045 static const WCHAR cmd_ConfigureLPTPortCommandOKW[] = {'C','o','n','f','i','g','u','r','e',
00046                                     'L','P','T','P','o','r','t',
00047                                     'C','o','m','m','a','n','d','O','K',0};
00048 static const WCHAR cmd_DeletePortW[] = {'D','e','l','e','t','e','P','o','r','t',0};
00049 static const WCHAR cmd_GetDefaultCommConfigW[] = {'G','e','t',
00050                                     'D','e','f','a','u','l','t',
00051                                     'C','o','m','m','C','o','n','f','i','g',0};
00052 static const WCHAR cmd_GetTransmissionRetryTimeoutW[] = {'G','e','t',
00053                                     'T','r','a','n','s','m','i','s','s','i','o','n',
00054                                     'R','e','t','r','y','T','i','m','e','o','u','t',0};
00055 static const WCHAR cmd_PortIsValidW[] = {'P','o','r','t','I','s','V','a','l','i','d',0};
00056 static const WCHAR cmd_SetDefaultCommConfigW[] = {'S','e','t',
00057                                     'D','e','f','a','u','l','t',
00058                                     'C','o','m','m','C','o','n','f','i','g',0};
00059 
00060 static const WCHAR fmt_uW[]  = {'%','u',0};
00061 static const WCHAR portname_LPT[]  = {'L','P','T',0};
00062 static const WCHAR portname_COM[]  = {'C','O','M',0};
00063 static const WCHAR portname_FILE[] = {'F','I','L','E',':',0};
00064 static const WCHAR portname_CUPS[] = {'C','U','P','S',':',0};
00065 static const WCHAR portname_LPR[]  = {'L','P','R',':',0};
00066 
00067 static const WCHAR XcvMonitorW[] = {',','X','c','v','M','o','n','i','t','o','r',' ',0};
00068 static const WCHAR XcvPortW[] = {',','X','c','v','P','o','r','t',' ',0};
00069 
00070 /*****************************************************/
00071 
00072 typedef struct tag_addportui_t {
00073     LPWSTR  portname;
00074     HANDLE  hXcv;
00075 } addportui_t;
00076 
00077 typedef struct tag_lptconfig_t {
00078     HANDLE  hXcv;
00079     DWORD   value;
00080 } lptconfig_t;
00081 
00082 
00083 static INT_PTR CALLBACK dlgproc_lptconfig(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
00084 
00085 /*****************************************************
00086  *   strdupWW [internal]
00087  */
00088 
00089 static LPWSTR strdupWW(LPCWSTR pPrefix, LPCWSTR pSuffix)
00090 {
00091     LPWSTR  ptr;
00092     DWORD   len;
00093 
00094     len = lstrlenW(pPrefix) + (pSuffix ? lstrlenW(pSuffix) : 0) + 1;
00095     ptr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
00096     if (ptr) {
00097         lstrcpyW(ptr, pPrefix);
00098         if (pSuffix) lstrcatW(ptr, pSuffix);
00099     }
00100     return ptr;
00101 }
00102 
00103 /*****************************************************
00104  *   dlg_configure_com [internal]
00105  *
00106  */
00107 
00108 static BOOL dlg_configure_com(HANDLE hXcv, HWND hWnd, PCWSTR pPortName)
00109 {
00110     COMMCONFIG cfg;
00111     LPWSTR shortname;
00112     DWORD status;
00113     DWORD dummy;
00114     DWORD len;
00115     BOOL  res;
00116 
00117     /* strip the colon (pPortName is never empty here) */
00118     len = lstrlenW(pPortName);
00119     shortname = HeapAlloc(GetProcessHeap(), 0, len  * sizeof(WCHAR));
00120     if (shortname) {
00121         memcpy(shortname, pPortName, (len -1) * sizeof(WCHAR));
00122         shortname[len-1] = '\0';
00123 
00124         /* get current settings */
00125         len = sizeof(cfg);
00126         status = ERROR_SUCCESS;
00127         res = XcvDataW( hXcv, cmd_GetDefaultCommConfigW,
00128                         (PBYTE) shortname,
00129                         (lstrlenW(shortname) +1) * sizeof(WCHAR),
00130                         (PBYTE) &cfg, len, &len, &status);
00131 
00132         if (res && (status == ERROR_SUCCESS)) {
00133             /* display the Dialog */
00134             res = CommConfigDialogW(pPortName, hWnd, &cfg);
00135             if (res) {
00136                 status = ERROR_SUCCESS;
00137                 /* set new settings */
00138                 res = XcvDataW(hXcv, cmd_SetDefaultCommConfigW,
00139                                (PBYTE) &cfg, len,
00140                                (PBYTE) &dummy, 0, &len, &status);
00141             }
00142         }
00143         HeapFree(GetProcessHeap(), 0, shortname);
00144         return res;
00145     }
00146     return FALSE;
00147 }
00148 
00149 
00150 /*****************************************************
00151  *   dlg_configure_lpt [internal]
00152  *
00153  */
00154 
00155 static BOOL dlg_configure_lpt(HANDLE hXcv, HWND hWnd)
00156 {
00157     lptconfig_t data;
00158     BOOL  res;
00159 
00160 
00161     data.hXcv = hXcv;
00162 
00163     res = DialogBoxParamW(LOCALUI_hInstance, MAKEINTRESOURCEW(LPTCONFIG_DIALOG), hWnd,
00164                                dlgproc_lptconfig, (LPARAM) &data);
00165 
00166     TRACE("got %u with %u\n", res, GetLastError());
00167 
00168     if (!res) SetLastError(ERROR_CANCELLED);
00169     return res;
00170 }
00171 
00172 /******************************************************************
00173  *  dlg_port_already_exists [internal]
00174  */
00175 
00176 static void dlg_port_already_exists(HWND hWnd, LPCWSTR portname)
00177 {
00178     WCHAR res_PortW[IDS_LOCALPORT_MAXLEN];
00179     WCHAR res_PortExistsW[IDS_PORTEXISTS_MAXLEN];
00180     LPWSTR  message;
00181     DWORD   len;
00182 
00183     res_PortW[0] = '\0';
00184     res_PortExistsW[0] = '\0';
00185     LoadStringW(LOCALUI_hInstance, IDS_LOCALPORT, res_PortW, IDS_LOCALPORT_MAXLEN);
00186     LoadStringW(LOCALUI_hInstance, IDS_PORTEXISTS, res_PortExistsW, IDS_PORTEXISTS_MAXLEN);
00187 
00188     len = lstrlenW(portname) + IDS_PORTEXISTS_MAXLEN + 1;
00189     message = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
00190     if (message) {
00191         message[0] = '\0';
00192         snprintfW(message, len, res_PortExistsW, portname);
00193         MessageBoxW(hWnd, message, res_PortW, MB_OK | MB_ICONERROR);
00194         HeapFree(GetProcessHeap(), 0, message);
00195     }
00196 }
00197 
00198 /******************************************************************
00199  *  dlg_invalid_portname [internal]
00200  */
00201 
00202 static void dlg_invalid_portname(HWND hWnd, LPCWSTR portname)
00203 {
00204     WCHAR res_PortW[IDS_LOCALPORT_MAXLEN];
00205     WCHAR res_InvalidNameW[IDS_INVALIDNAME_MAXLEN];
00206     LPWSTR  message;
00207     DWORD   len;
00208 
00209     res_PortW[0] = '\0';
00210     res_InvalidNameW[0] = '\0';
00211     LoadStringW(LOCALUI_hInstance, IDS_LOCALPORT, res_PortW, IDS_LOCALPORT_MAXLEN);
00212     LoadStringW(LOCALUI_hInstance, IDS_INVALIDNAME, res_InvalidNameW, IDS_INVALIDNAME_MAXLEN);
00213 
00214     len = lstrlenW(portname) + IDS_INVALIDNAME_MAXLEN;
00215     message = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
00216     if (message) {
00217         message[0] = '\0';
00218         snprintfW(message, len, res_InvalidNameW, portname);
00219         MessageBoxW(hWnd, message, res_PortW, MB_OK | MB_ICONERROR);
00220         HeapFree(GetProcessHeap(), 0, message);
00221     }
00222 }
00223 
00224 /******************************************************************
00225  * display the Dialog "Nothing to configure"
00226  *
00227  */
00228 
00229 static void dlg_nothingtoconfig(HWND hWnd)
00230 {
00231     WCHAR res_PortW[IDS_LOCALPORT_MAXLEN];
00232     WCHAR res_nothingW[IDS_NOTHINGTOCONFIG_MAXLEN];
00233 
00234     res_PortW[0] = '\0';
00235     res_nothingW[0] = '\0';
00236     LoadStringW(LOCALUI_hInstance, IDS_LOCALPORT, res_PortW, IDS_LOCALPORT_MAXLEN);
00237     LoadStringW(LOCALUI_hInstance, IDS_NOTHINGTOCONFIG, res_nothingW, IDS_NOTHINGTOCONFIG_MAXLEN);
00238 
00239     MessageBoxW(hWnd, res_nothingW, res_PortW, MB_OK | MB_ICONINFORMATION);
00240 }
00241 
00242 /******************************************************************
00243  *  dlg_win32error [internal]
00244  */
00245 
00246 static void dlg_win32error(HWND hWnd, DWORD lasterror)
00247 {
00248     WCHAR res_PortW[IDS_LOCALPORT_MAXLEN];
00249     LPWSTR  message = NULL;
00250     DWORD   res;
00251 
00252     res_PortW[0] = '\0';
00253     LoadStringW(LOCALUI_hInstance, IDS_LOCALPORT, res_PortW, IDS_LOCALPORT_MAXLEN);
00254 
00255 
00256     res = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
00257                         NULL, lasterror, 0, (LPWSTR) &message, 0, NULL);
00258 
00259     if (res > 0) {
00260         MessageBoxW(hWnd, message, res_PortW, MB_OK | MB_ICONERROR);
00261         LocalFree(message);
00262     }
00263 }
00264 
00265 /*****************************************************************************
00266  *
00267  */
00268 
00269 static INT_PTR CALLBACK dlgproc_addport(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
00270 {
00271     addportui_t * data;
00272     DWORD   status;
00273     DWORD   dummy;
00274     DWORD   len;
00275     DWORD   res;
00276 
00277     switch(msg)
00278     {
00279     case WM_INITDIALOG:
00280         SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
00281         return TRUE;
00282 
00283     case WM_COMMAND:
00284         if (wparam == MAKEWPARAM(IDOK, BN_CLICKED))
00285         {
00286             data = (addportui_t *) GetWindowLongPtrW(hwnd, DWLP_USER);
00287             /* length in WCHAR, without the '\0' */
00288             len = SendDlgItemMessageW(hwnd, ADDPORT_EDIT, WM_GETTEXTLENGTH, 0, 0);
00289             data->portname = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
00290 
00291             if (!data->portname) {
00292                 EndDialog(hwnd, FALSE);
00293                 return TRUE;
00294             }
00295             /* length is in WCHAR, including the '\0' */
00296             GetDlgItemTextW(hwnd, ADDPORT_EDIT, data->portname, len + 1);
00297             status = ERROR_SUCCESS;
00298             res = XcvDataW( data->hXcv, cmd_PortIsValidW, (PBYTE) data->portname,
00299                             (lstrlenW(data->portname) + 1) * sizeof(WCHAR),
00300                             (PBYTE) &dummy, 0, &len, &status);
00301 
00302             TRACE("got %u with status %u\n", res, status);
00303             if (res && (status == ERROR_SUCCESS)) {
00304                 /* The caller must free data->portname */
00305                 EndDialog(hwnd, TRUE);
00306                 return TRUE;
00307             }
00308 
00309             if (res && (status == ERROR_INVALID_NAME)) {
00310                 dlg_invalid_portname(hwnd, data->portname);
00311                 HeapFree(GetProcessHeap(), 0, data->portname);
00312                 data->portname = NULL;
00313                 return TRUE;
00314             }
00315 
00316             dlg_win32error(hwnd, status);
00317             HeapFree(GetProcessHeap(), 0, data->portname);
00318             data->portname = NULL;
00319             return TRUE;
00320         }
00321 
00322         if (wparam == MAKEWPARAM(IDCANCEL, BN_CLICKED))
00323         {
00324             EndDialog(hwnd, FALSE);
00325             return TRUE;
00326         }
00327         return FALSE;
00328     }
00329     return FALSE;
00330 }
00331 
00332 /*****************************************************************************
00333  *   dlgproc_lptconfig  [internal]
00334  *
00335  * Our message-proc is simple, as the range-check is done only during the
00336  * command "OK" and the dialog is set to the start-value at "out of range".
00337  *
00338  * Native localui.dll does the check during keyboard-input and set the dialog
00339  * to the previous value.
00340  *
00341  */
00342 
00343 static INT_PTR CALLBACK dlgproc_lptconfig(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
00344 {
00345     lptconfig_t * data;
00346     WCHAR   bufferW[16];
00347     DWORD   status;
00348     DWORD   dummy;
00349     DWORD   len;
00350     DWORD   res;
00351 
00352 
00353     switch(msg)
00354     {
00355     case WM_INITDIALOG:
00356         SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
00357         data = (lptconfig_t *) lparam;
00358 
00359         /* Get current setting */
00360         data->value = 45;
00361         status = ERROR_SUCCESS;
00362         res = XcvDataW( data->hXcv, cmd_GetTransmissionRetryTimeoutW,
00363                         (PBYTE) &dummy, 0,
00364                         (PBYTE) &data->value, sizeof(data->value), &len, &status);
00365 
00366         TRACE("got %u with status %u\n", res, status);
00367 
00368         /* Set current setting as the initial value in the Dialog */
00369         SetDlgItemInt(hwnd, LPTCONFIG_EDIT, data->value, FALSE);
00370         return TRUE;
00371 
00372     case WM_COMMAND:
00373         if (wparam == MAKEWPARAM(IDOK, BN_CLICKED))
00374         {
00375             data = (lptconfig_t *) GetWindowLongPtrW(hwnd, DWLP_USER);
00376 
00377             status = FALSE;
00378             res = GetDlgItemInt(hwnd, LPTCONFIG_EDIT, (BOOL *) &status, FALSE);
00379             /* length is in WCHAR, including the '\0' */
00380             GetDlgItemTextW(hwnd, LPTCONFIG_EDIT, bufferW, sizeof(bufferW) / sizeof(bufferW[0]));
00381             TRACE("got %s and %u (translated: %u)\n", debugstr_w(bufferW), res, status);
00382 
00383             /* native localui.dll use the same limits */
00384             if ((res > 0) && (res < 1000000) && status) {
00385                 sprintfW(bufferW, fmt_uW, res);
00386                 res = XcvDataW( data->hXcv, cmd_ConfigureLPTPortCommandOKW,
00387                         (PBYTE) bufferW,
00388                         (lstrlenW(bufferW) +1) * sizeof(WCHAR),
00389                         (PBYTE) &dummy, 0, &len, &status);
00390 
00391                 TRACE("got %u with status %u\n", res, status);
00392                 EndDialog(hwnd, TRUE);
00393                 return TRUE;
00394             }
00395 
00396             /* Set initial value and rerun the Dialog */
00397             SetDlgItemInt(hwnd, LPTCONFIG_EDIT, data->value, FALSE);
00398             return TRUE;
00399         }
00400 
00401         if (wparam == MAKEWPARAM(IDCANCEL, BN_CLICKED))
00402         {
00403             EndDialog(hwnd, FALSE);
00404             return TRUE;
00405         }
00406         return FALSE;
00407     }
00408     return FALSE;
00409 }
00410 
00411 
00412 /*****************************************************
00413  * get_type_from_name (internal)
00414  *
00415  */
00416 
00417 static DWORD get_type_from_name(LPCWSTR name)
00418 {
00419     HANDLE  hfile;
00420 
00421     if (!strncmpiW(name, portname_LPT, sizeof(portname_LPT) / sizeof(WCHAR) -1))
00422         return PORT_IS_LPT;
00423 
00424     if (!strncmpiW(name, portname_COM, sizeof(portname_COM) / sizeof(WCHAR) -1))
00425         return PORT_IS_COM;
00426 
00427     if (!strcmpiW(name, portname_FILE))
00428         return PORT_IS_FILE;
00429 
00430     if (name[0] == '/')
00431         return PORT_IS_UNIXNAME;
00432 
00433     if (name[0] == '|')
00434         return PORT_IS_PIPE;
00435 
00436     if (!strncmpW(name, portname_CUPS, sizeof(portname_CUPS) / sizeof(WCHAR) -1))
00437         return PORT_IS_CUPS;
00438 
00439     if (!strncmpW(name, portname_LPR, sizeof(portname_LPR) / sizeof(WCHAR) -1))
00440         return PORT_IS_LPR;
00441 
00442     /* Must be a file or a directory. Does the file exist ? */
00443     hfile = CreateFileW(name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
00444     TRACE("%p for OPEN_EXISTING on %s\n", hfile, debugstr_w(name));
00445     if (hfile == INVALID_HANDLE_VALUE) {
00446         /* Can we create the file? */
00447         hfile = CreateFileW(name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
00448         TRACE("%p for OPEN_ALWAYS\n", hfile);
00449     }
00450     if (hfile != INVALID_HANDLE_VALUE) {
00451         CloseHandle(hfile);
00452         return PORT_IS_FILENAME;
00453     }
00454     /* We can't use the name. use GetLastError() for the reason */
00455     return PORT_IS_UNKNOWN;
00456 }
00457 
00458 /*****************************************************
00459  *   open_monitor_by_name [internal]
00460  *
00461  */
00462 static BOOL open_monitor_by_name(LPCWSTR pPrefix, LPCWSTR pPort, HANDLE * phandle)
00463 {
00464     PRINTER_DEFAULTSW pd;
00465     LPWSTR  fullname;
00466     BOOL    res;
00467 
00468     * phandle = 0;
00469     TRACE("(%s,%s)\n", debugstr_w(pPrefix),debugstr_w(pPort) );
00470 
00471     fullname = strdupWW(pPrefix, pPort);
00472     pd.pDatatype = NULL;
00473     pd.pDevMode  = NULL;
00474     pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
00475 
00476     res = OpenPrinterW(fullname, phandle, &pd);
00477     HeapFree(GetProcessHeap(), 0, fullname);
00478     return res;
00479 }
00480 
00481 /*****************************************************
00482  *   localui_AddPortUI [exported through MONITORUI]
00483  *
00484  * Display a Dialog to add a local Port
00485  *
00486  * PARAMS
00487  *  pName       [I] Servername or NULL (local Computer)
00488  *  hWnd        [I] Handle to parent Window for the Dialog-Box or NULL
00489  *  pMonitorName[I] Name of the Monitor, that should be used to add a Port or NULL
00490  *  ppPortName  [O] PTR to PTR of a buffer, that receive the Name of the new Port or NULL
00491  *
00492  * RETURNS
00493  *  Success: TRUE
00494  *  Failure: FALSE
00495  *
00496  * NOTES
00497  * The caller must free the buffer (returned in ppPortName) with GlobalFree().
00498  * Native localui.dll failed with ERROR_INVALID_PARAMETER, when the user tried
00499  * to add a Port, that start with "COM" or "LPT".
00500  *
00501  */
00502 static BOOL WINAPI localui_AddPortUI(PCWSTR pName, HWND hWnd, PCWSTR pMonitorName, PWSTR *ppPortName)
00503 {
00504     addportui_t data;
00505     HANDLE  hXcv;
00506     DWORD   needed;
00507     DWORD   dummy;
00508     DWORD   status;
00509     DWORD   res = FALSE;
00510 
00511     TRACE(  "(%s, %p, %s, %p) (*ppPortName: %p)\n", debugstr_w(pName), hWnd,
00512             debugstr_w(pMonitorName), ppPortName, ppPortName ? *ppPortName : NULL);
00513 
00514     if (open_monitor_by_name(XcvMonitorW, pMonitorName, &hXcv)) {
00515 
00516         ZeroMemory(&data, sizeof(addportui_t));
00517         data.hXcv = hXcv;
00518         res = DialogBoxParamW(LOCALUI_hInstance, MAKEINTRESOURCEW(ADDPORT_DIALOG), hWnd,
00519                                dlgproc_addport, (LPARAM) &data);
00520 
00521         TRACE("got %u with %u for %s\n", res, GetLastError(), debugstr_w(data.portname));
00522 
00523         if (ppPortName) *ppPortName = NULL;
00524 
00525         if (res) {
00526             res = XcvDataW(hXcv, cmd_AddPortW, (PBYTE) data.portname,
00527                             (lstrlenW(data.portname)+1) * sizeof(WCHAR),
00528                             (PBYTE) &dummy, 0, &needed, &status);
00529 
00530             TRACE("got %u with status %u\n", res, status);
00531             if (res && (status == ERROR_SUCCESS) && ppPortName) {
00532                 /* Native localui uses GlobalAlloc also.
00533                    The caller must GlobalFree the buffer */
00534                 *ppPortName = GlobalAlloc(GPTR, (lstrlenW(data.portname)+1) * sizeof(WCHAR));
00535                 if (*ppPortName) lstrcpyW(*ppPortName, data.portname);
00536             }
00537 
00538             if (res && (status == ERROR_ALREADY_EXISTS)) {
00539                 dlg_port_already_exists(hWnd, data.portname);
00540                 /* Native localui also return "TRUE" from AddPortUI in this case */
00541             }
00542 
00543             HeapFree(GetProcessHeap(), 0, data.portname);
00544         }
00545         else
00546         {
00547             SetLastError(ERROR_CANCELLED);
00548         }
00549         ClosePrinter(hXcv);
00550     }
00551 
00552     TRACE("=> %u with %u\n", res, GetLastError());
00553     return res;
00554 }
00555 
00556 
00557 /*****************************************************
00558  *   localui_ConfigurePortUI [exported through MONITORUI]
00559  *
00560  * Display the Configuration-Dialog for a specific Port
00561  *
00562  * PARAMS
00563  *  pName     [I] Servername or NULL (local Computer)
00564  *  hWnd      [I] Handle to parent Window for the Dialog-Box or NULL
00565  *  pPortName [I] Name of the Port, that should be configured
00566  *
00567  * RETURNS
00568  *  Success: TRUE
00569  *  Failure: FALSE
00570  *
00571  */
00572 static BOOL WINAPI localui_ConfigurePortUI(PCWSTR pName, HWND hWnd, PCWSTR pPortName)
00573 {
00574     HANDLE  hXcv;
00575     DWORD   res;
00576 
00577     TRACE("(%s, %p, %s)\n", debugstr_w(pName), hWnd, debugstr_w(pPortName));
00578     if (open_monitor_by_name(XcvPortW, pPortName, &hXcv)) {
00579 
00580         res = get_type_from_name(pPortName);
00581         switch(res)
00582         {
00583 
00584         case PORT_IS_COM:
00585             res = dlg_configure_com(hXcv, hWnd, pPortName);
00586             break;
00587 
00588         case PORT_IS_LPT:
00589             res = dlg_configure_lpt(hXcv, hWnd);
00590             break;
00591 
00592         default:
00593             dlg_nothingtoconfig(hWnd);
00594             SetLastError(ERROR_CANCELLED);
00595             res = FALSE;
00596         }
00597 
00598         ClosePrinter(hXcv);
00599         return res;
00600     }
00601     return FALSE;
00602 
00603 }
00604 
00605 /*****************************************************
00606  *   localui_DeletePortUI [exported through MONITORUI]
00607  *
00608  * Delete a specific Port
00609  *
00610  * PARAMS
00611  *  pName     [I] Servername or NULL (local Computer)
00612  *  hWnd      [I] Handle to parent Window
00613  *  pPortName [I] Name of the Port, that should be deleted
00614  *
00615  * RETURNS
00616  *  Success: TRUE
00617  *  Failure: FALSE
00618  *
00619  * NOTES
00620  *  Native localui does not allow to delete a COM / LPT - Port (ERROR_NOT_SUPPORTED)
00621  *
00622  */
00623 static BOOL WINAPI localui_DeletePortUI(PCWSTR pName, HWND hWnd, PCWSTR pPortName)
00624 {
00625     HANDLE  hXcv;
00626     DWORD   dummy;
00627     DWORD   needed;
00628     DWORD   status;
00629 
00630     TRACE("(%s, %p, %s)\n", debugstr_w(pName), hWnd, debugstr_w(pPortName));
00631 
00632     if ((!pPortName) || (!pPortName[0])) {
00633         SetLastError(ERROR_INVALID_PARAMETER);
00634         return FALSE;
00635     }
00636 
00637     if (open_monitor_by_name(XcvPortW, pPortName, &hXcv)) {
00638         /* native localui tests here for LPT / COM - Ports and failed with
00639            ERROR_NOT_SUPPORTED. */
00640         if (XcvDataW(hXcv, cmd_DeletePortW, (LPBYTE) pPortName,
00641             (lstrlenW(pPortName)+1) * sizeof(WCHAR), (LPBYTE) &dummy, 0, &needed, &status)) {
00642 
00643             ClosePrinter(hXcv);
00644             if (status != ERROR_SUCCESS) SetLastError(status);
00645             return (status == ERROR_SUCCESS);
00646         }
00647         ClosePrinter(hXcv);
00648         return FALSE;
00649     }
00650     SetLastError(ERROR_UNKNOWN_PORT);
00651     return FALSE;
00652 }
00653 
00654 /*****************************************************
00655  *      InitializePrintMonitorUI  (LOCALUI.@)
00656  *
00657  * Initialize the User-Interface for the Local Ports
00658  *
00659  * RETURNS
00660  *  Success: Pointer to a MONITORUI Structure
00661  *  Failure: NULL
00662  *
00663  */
00664 
00665 PMONITORUI WINAPI InitializePrintMonitorUI(void)
00666 {
00667     static MONITORUI mymonitorui =
00668     {
00669         sizeof(MONITORUI),
00670         localui_AddPortUI,
00671         localui_ConfigurePortUI,
00672         localui_DeletePortUI
00673     };
00674 
00675     TRACE("=> %p\n", &mymonitorui);
00676     return &mymonitorui;
00677 }
00678 
00679 /*****************************************************
00680  *      DllMain
00681  */
00682 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
00683 {
00684     TRACE("(%p, %d, %p)\n",hinstDLL, fdwReason, lpvReserved);
00685 
00686     switch(fdwReason)
00687     {
00688         case DLL_PROCESS_ATTACH:
00689             DisableThreadLibraryCalls( hinstDLL );
00690             LOCALUI_hInstance = hinstDLL;
00691             break;
00692     }
00693     return TRUE;
00694 }

Generated on Sun May 27 2012 04:24:36 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.