2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2000-07-15 23:35:55 +02:00
|
|
|
* This DLL contains the user interface for the serial driver.
|
2000-07-16 17:44:22 +02:00
|
|
|
* a dialog box to configure the specified COMM port
|
2000-07-15 23:35:55 +02:00
|
|
|
* an interface to the control panel (??)
|
|
|
|
* functions to load and save default configuration
|
|
|
|
*
|
|
|
|
* Eventually the 32 bit comm port driver could be moved into here
|
|
|
|
* and interfaced to KERNEL32 using the WIN95 or WINNT comm driver interface.
|
|
|
|
* This way, different driver DLLS could be written to support other
|
|
|
|
* serial interfaces, such as X.25, etc.
|
|
|
|
*
|
|
|
|
* Basic structure copied from COMCTL32 code.
|
|
|
|
*
|
2004-10-26 02:16:39 +02:00
|
|
|
* Copyright 2000, 2004 Mike McCormack
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-07-15 23:35:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-08-08 22:49:16 +02:00
|
|
|
#include <stdio.h>
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-07-15 23:35:55 +02:00
|
|
|
#include "winbase.h"
|
2019-06-20 09:09:50 +02:00
|
|
|
#include "winnls.h"
|
2000-07-15 23:35:55 +02:00
|
|
|
#include "winreg.h"
|
2000-08-10 00:35:05 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-07-15 23:35:55 +02:00
|
|
|
#include "serialui.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(comm);
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2007-01-27 19:10:19 +01:00
|
|
|
static HMODULE SERIALUI_hModule;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2002-11-05 00:53:41 +01:00
|
|
|
* DllMain [Internal] Initializes the internal 'SERIALUI.DLL'.
|
2000-07-15 23:35:55 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2000-07-16 17:44:22 +02:00
|
|
|
* hinstDLL [I] handle to the DLL's instance
|
2000-07-15 23:35:55 +02:00
|
|
|
* fdwReason [I]
|
2000-07-16 17:44:22 +02:00
|
|
|
* lpvReserved [I] reserved, must be NULL
|
2000-07-15 23:35:55 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
2000-07-15 23:35:55 +02:00
|
|
|
{
|
2006-10-06 23:01:28 +02:00
|
|
|
TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
switch (fdwReason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2003-06-30 22:53:48 +02:00
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
2001-01-17 23:03:18 +01:00
|
|
|
SERIALUI_hModule = hinstDLL;
|
2000-07-15 23:35:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* EnumPropPages (SERIALUI.2)
|
2000-07-15 23:35:55 +02:00
|
|
|
*
|
|
|
|
* Called by the device manager to add prop sheets in Control Panel ???
|
2002-06-01 01:06:46 +02:00
|
|
|
* Pointed to in Win98 registry by
|
2000-07-15 23:35:55 +02:00
|
|
|
* \System\CurrentControlSet\Services\Class\ports\0000\EnumPropPages =
|
|
|
|
* "serialui.dll,EnumPropPages"
|
|
|
|
*/
|
|
|
|
typedef LPVOID LPDEVICE_INFO;
|
|
|
|
typedef LPVOID LPFNADDPROPSHEETPAGE;
|
2004-10-26 02:16:39 +02:00
|
|
|
BOOL WINAPI EnumPropPages(LPDEVICE_INFO pdi, LPFNADDPROPSHEETPAGE pfnAdd, LPARAM lParam )
|
2000-07-15 23:35:55 +02:00
|
|
|
{
|
|
|
|
FIXME("(%p %p %lx)\n",pdi,pfnAdd,lParam);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These data structures are convert from values used in fields of a DCB
|
|
|
|
* to strings used in the CommConfigDialog.
|
|
|
|
*/
|
|
|
|
typedef struct tagPARAM2STRDATA
|
|
|
|
{
|
|
|
|
DWORD val;
|
2013-09-25 10:39:19 +02:00
|
|
|
const CHAR *name;
|
2000-07-15 23:35:55 +02:00
|
|
|
} PARAM2STRDATA, *LPPARAM2STRDATA;
|
|
|
|
|
|
|
|
typedef struct tagPARAM2STR
|
|
|
|
{
|
|
|
|
DWORD dwSize;
|
|
|
|
LPPARAM2STRDATA data;
|
|
|
|
} PARAM2STR, *LPPARAM2STR;
|
2007-03-08 23:15:27 +01:00
|
|
|
typedef const PARAM2STR *LPCPARAM2STR;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
static PARAM2STRDATA SERIALUI_Baud2StrData[]={
|
|
|
|
{110, "110"}, {300, "300"}, {600, "600"}, {1200, "1200"},
|
|
|
|
{2400, "2400"}, {4800, "4800"}, {9600, "9600"}, {14400, "14400"},
|
|
|
|
{19200, "19200"}, {38400L, "38400"}, {56000L, "56000"}, {57600L, "57600"},
|
|
|
|
{115200L, "115200"}, {128000L, "128000"}, {256000L, "256000"}
|
|
|
|
};
|
2018-07-05 22:07:20 +02:00
|
|
|
static PARAM2STR SERIALUI_Baud2Str={ ARRAY_SIZE(SERIALUI_Baud2StrData), SERIALUI_Baud2StrData };
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
static PARAM2STRDATA SERIALUI_Parity2StrData[]={
|
2000-07-15 23:35:55 +02:00
|
|
|
{NOPARITY,"None"}, {ODDPARITY,"Odd"}, {EVENPARITY,"Even"}, {MARKPARITY,"Mark"},
|
|
|
|
{SPACEPARITY,"Space"}
|
|
|
|
};
|
2018-07-05 22:07:20 +02:00
|
|
|
static PARAM2STR SERIALUI_Parity2Str={ ARRAY_SIZE(SERIALUI_Parity2StrData), SERIALUI_Parity2StrData };
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
static PARAM2STRDATA SERIALUI_Stop2StrData[]={
|
|
|
|
{ONESTOPBIT,"1"}, {ONE5STOPBITS,"1.5"}, {TWOSTOPBITS,"2"}
|
|
|
|
};
|
2018-07-05 22:07:20 +02:00
|
|
|
static PARAM2STR SERIALUI_Stop2Str={ ARRAY_SIZE(SERIALUI_Stop2StrData), SERIALUI_Stop2StrData };
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
static PARAM2STRDATA SERIALUI_Data2StrData[]={
|
|
|
|
{5,"5"}, {6,"6"}, {7,"7"}, {8, "8"}, {16,"16"}
|
|
|
|
};
|
2018-07-05 22:07:20 +02:00
|
|
|
static PARAM2STR SERIALUI_Data2Str={ ARRAY_SIZE(SERIALUI_Data2StrData), SERIALUI_Data2StrData };
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
static PARAM2STRDATA SERIALUI_Flow2StrData[]={
|
|
|
|
{0,"None"}, {1,"Hardware (RTS/CTS)"}, {2,"Software (XON/XOFF)"}
|
|
|
|
};
|
2018-07-05 22:07:20 +02:00
|
|
|
static PARAM2STR SERIALUI_Flow2Str={ ARRAY_SIZE(SERIALUI_Flow2StrData), SERIALUI_Flow2StrData };
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add all the fields to a combo box and highlight the current value
|
|
|
|
*/
|
|
|
|
static void SERIALUI_AddConfItems(HWND hDlg, DWORD id, LPCPARAM2STR table, DWORD dwVal)
|
|
|
|
{
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
|
|
|
int n;
|
2000-07-15 23:35:55 +02:00
|
|
|
HWND hControl = GetDlgItem(hDlg,id);
|
|
|
|
|
|
|
|
if(!hControl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(i=0; i<table->dwSize; i++)
|
|
|
|
{
|
|
|
|
n = SendMessageA(hControl, CB_ADDSTRING, 0L, (LPARAM)table->data[i].name);
|
|
|
|
if(dwVal == table->data[i].val)
|
|
|
|
{
|
2010-11-08 11:37:55 +01:00
|
|
|
SendMessageA(hControl, CB_SETCURSEL, n, 0);
|
2000-07-15 23:35:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-04-21 07:17:27 +02:00
|
|
|
* Get the current selection of the given combo box and set a DCB field to
|
2000-07-15 23:35:55 +02:00
|
|
|
* the value matching that selection.
|
|
|
|
*/
|
|
|
|
static BOOL SERIALUI_GetConfItems(HWND hDlg, DWORD id, LPCPARAM2STR table, LPDWORD lpdwVal)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
CHAR lpEntry[20];
|
|
|
|
HWND hControl = GetDlgItem(hDlg,id);
|
|
|
|
|
|
|
|
if( (!hControl) || (!lpdwVal))
|
|
|
|
{
|
2006-10-06 23:01:28 +02:00
|
|
|
TRACE("Couldn't get window handle for item %x\n",id);
|
2000-07-15 23:35:55 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-18 21:45:22 +02:00
|
|
|
if(!GetWindowTextA(hControl, &lpEntry[0], sizeof(lpEntry)))
|
2000-07-15 23:35:55 +02:00
|
|
|
{
|
2006-10-06 23:01:28 +02:00
|
|
|
TRACE("Couldn't get window text for item %x\n",id);
|
2000-07-15 23:35:55 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* TRACE("%ld contains %s\n",id, lpEntry); */
|
|
|
|
|
|
|
|
for(i=0; i<table->dwSize; i++)
|
|
|
|
{
|
|
|
|
if(!lstrcmpA(table->data[i].name,lpEntry))
|
|
|
|
{
|
|
|
|
*lpdwVal = table->data[i].val;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Both the enumerated values CBR_XXXX and integer baud rates are valid
|
|
|
|
* dcb.BaudRate. This code is to convert back and forth between CBR_ style
|
|
|
|
* and integers. The dialog box uses integer values.
|
|
|
|
*/
|
2007-02-22 00:25:25 +01:00
|
|
|
static const DWORD SERIALUI_BaudConvertTable[] = {
|
2000-07-15 23:35:55 +02:00
|
|
|
CBR_110, 110, CBR_300, 300, CBR_600, 600, CBR_1200, 1200,
|
|
|
|
CBR_2400, 2400, CBR_4800, 4800, CBR_9600, 9600, CBR_14400, 14400,
|
|
|
|
CBR_19200, 19200, CBR_38400, 38400, CBR_56000, 56000, CBR_57600, 57600,
|
|
|
|
CBR_115200, 115200, CBR_128000, 128000, CBR_256000, 256000
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL SERIALUI_MakeBaudDword(LPDWORD lpdwBaudRate)
|
|
|
|
{
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2018-08-08 11:30:16 +02:00
|
|
|
for(i=0; i<ARRAY_SIZE(SERIALUI_BaudConvertTable); i+=2)
|
2000-07-15 23:35:55 +02:00
|
|
|
{
|
|
|
|
if(*lpdwBaudRate == SERIALUI_BaudConvertTable[i])
|
|
|
|
{
|
|
|
|
*lpdwBaudRate = SERIALUI_BaudConvertTable[i+1];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SERIALUI_MakeBaudEnum(LPDWORD lpdwBaudRate)
|
|
|
|
{
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2018-08-08 11:30:16 +02:00
|
|
|
for(i=0; i<ARRAY_SIZE(SERIALUI_BaudConvertTable); i+=2)
|
2000-07-15 23:35:55 +02:00
|
|
|
{
|
|
|
|
if(*lpdwBaudRate == SERIALUI_BaudConvertTable[i+1])
|
|
|
|
{
|
|
|
|
*lpdwBaudRate = SERIALUI_BaudConvertTable[i];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct tagSERIALUI_DialogInfo
|
|
|
|
{
|
2004-10-26 02:16:39 +02:00
|
|
|
LPCWSTR lpszDevice;
|
2000-07-15 23:35:55 +02:00
|
|
|
LPCOMMCONFIG lpCommConfig;
|
|
|
|
BOOL bConvert; /* baud rate was converted to a DWORD */
|
|
|
|
DWORD dwFlowControl; /* old flow control */
|
|
|
|
} SERIALUI_DialogInfo;
|
|
|
|
|
|
|
|
static void SERIALUI_DCBToDialogInfo(HWND hDlg, SERIALUI_DialogInfo *info)
|
|
|
|
{
|
|
|
|
DWORD dwBaudRate, dwStopBits, dwParity, dwByteSize, dwFlowControl;
|
|
|
|
LPDCB lpdcb = &info->lpCommConfig->dcb;
|
|
|
|
|
|
|
|
/* pass integer pointers to SERIALUI_ dialog config fns */
|
|
|
|
dwBaudRate = lpdcb->BaudRate;
|
|
|
|
dwStopBits = lpdcb->StopBits;
|
|
|
|
dwParity = lpdcb->Parity;
|
|
|
|
dwByteSize = lpdcb->ByteSize;
|
|
|
|
|
|
|
|
/* map flow control state, if it looks normal */
|
|
|
|
if((lpdcb->fRtsControl == RTS_CONTROL_HANDSHAKE) ||
|
2004-12-09 15:07:59 +01:00
|
|
|
(lpdcb->fOutxCtsFlow)) {
|
2000-07-15 23:35:55 +02:00
|
|
|
dwFlowControl = 1;
|
|
|
|
} else if(lpdcb->fOutX || lpdcb->fInX) {
|
|
|
|
dwFlowControl = 2;
|
|
|
|
} else {
|
|
|
|
dwFlowControl = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->bConvert = SERIALUI_MakeBaudDword(&dwBaudRate);
|
|
|
|
|
|
|
|
SERIALUI_AddConfItems( hDlg, IDC_BAUD, &SERIALUI_Baud2Str ,dwBaudRate);
|
|
|
|
SERIALUI_AddConfItems( hDlg, IDC_STOP, &SERIALUI_Stop2Str ,dwStopBits);
|
|
|
|
SERIALUI_AddConfItems( hDlg, IDC_PARITY, &SERIALUI_Parity2Str ,dwParity);
|
|
|
|
SERIALUI_AddConfItems( hDlg, IDC_DATA, &SERIALUI_Data2Str ,dwByteSize);
|
|
|
|
SERIALUI_AddConfItems( hDlg, IDC_FLOW, &SERIALUI_Flow2Str, dwFlowControl );
|
|
|
|
|
|
|
|
info->dwFlowControl = dwFlowControl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SERIALUI_DialogInfoToDCB(HWND hDlg, SERIALUI_DialogInfo *info)
|
|
|
|
{
|
|
|
|
DWORD dwBaudRate, dwStopBits, dwParity, dwByteSize, dwFlowControl;
|
|
|
|
LPDCB lpdcb = &info->lpCommConfig->dcb;
|
|
|
|
|
|
|
|
SERIALUI_GetConfItems( hDlg, IDC_BAUD, &SERIALUI_Baud2Str, &dwBaudRate);
|
|
|
|
SERIALUI_GetConfItems( hDlg, IDC_STOP, &SERIALUI_Stop2Str, &dwStopBits);
|
|
|
|
SERIALUI_GetConfItems( hDlg, IDC_PARITY, &SERIALUI_Parity2Str, &dwParity);
|
|
|
|
SERIALUI_GetConfItems( hDlg, IDC_DATA, &SERIALUI_Data2Str, &dwByteSize);
|
|
|
|
SERIALUI_GetConfItems( hDlg, IDC_FLOW, &SERIALUI_Flow2Str, &dwFlowControl );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-10-06 23:01:28 +02:00
|
|
|
TRACE("baud=%d stop=%d parity=%d data=%d flow=%d\n",
|
2000-07-15 23:35:55 +02:00
|
|
|
dwBaudRate, dwStopBits, dwParity, dwByteSize, dwFlowControl);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 23:35:55 +02:00
|
|
|
lpdcb->BaudRate = dwBaudRate;
|
|
|
|
lpdcb->StopBits = dwStopBits;
|
|
|
|
lpdcb->Parity = dwParity;
|
|
|
|
lpdcb->ByteSize = dwByteSize;
|
|
|
|
|
|
|
|
/* try not to change flow control if the user didn't change it */
|
|
|
|
if(info->dwFlowControl != dwFlowControl)
|
|
|
|
{
|
|
|
|
switch(dwFlowControl)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
lpdcb->fOutxCtsFlow = FALSE;
|
|
|
|
lpdcb->fOutxDsrFlow = FALSE;
|
|
|
|
lpdcb->fDtrControl = DTR_CONTROL_DISABLE;
|
|
|
|
lpdcb->fOutX = FALSE;
|
|
|
|
lpdcb->fInX = FALSE;
|
|
|
|
lpdcb->fRtsControl = RTS_CONTROL_DISABLE;
|
|
|
|
break;
|
|
|
|
case 1: /* CTS/RTS */
|
|
|
|
lpdcb->fOutxCtsFlow = TRUE;
|
|
|
|
lpdcb->fOutxDsrFlow = FALSE;
|
|
|
|
lpdcb->fDtrControl = DTR_CONTROL_DISABLE;
|
|
|
|
lpdcb->fOutX = FALSE;
|
|
|
|
lpdcb->fInX = FALSE;
|
|
|
|
lpdcb->fRtsControl = RTS_CONTROL_HANDSHAKE;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
lpdcb->fOutxCtsFlow = FALSE;
|
|
|
|
lpdcb->fOutxDsrFlow = FALSE;
|
|
|
|
lpdcb->fDtrControl = DTR_CONTROL_DISABLE;
|
|
|
|
lpdcb->fOutX = TRUE;
|
|
|
|
lpdcb->fInX = TRUE;
|
|
|
|
lpdcb->fRtsControl = RTS_CONTROL_DISABLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(info->bConvert)
|
|
|
|
SERIALUI_MakeBaudEnum(&lpdcb->BaudRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SERIALUI_ConfigDialogProc
|
|
|
|
*
|
|
|
|
* Shows a dialog for configuring a COMM port
|
|
|
|
*/
|
2007-01-27 19:10:19 +01:00
|
|
|
static INT_PTR CALLBACK SERIALUI_ConfigDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2000-07-15 23:35:55 +02:00
|
|
|
{
|
2011-11-30 17:51:45 +01:00
|
|
|
WCHAR szTitle[128], format[40];
|
2000-07-15 23:35:55 +02:00
|
|
|
SERIALUI_DialogInfo *info;
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
info = (SERIALUI_DialogInfo*) lParam;
|
|
|
|
if(!info)
|
|
|
|
return FALSE;
|
2005-02-15 22:51:06 +01:00
|
|
|
SetWindowLongPtrW(hWnd, DWLP_USER, lParam);
|
2018-08-08 11:30:16 +02:00
|
|
|
GetWindowTextW(hWnd, format, ARRAY_SIZE(format));
|
2019-06-20 09:09:50 +02:00
|
|
|
swprintf(szTitle, ARRAY_SIZE(szTitle), format, info->lpszDevice);
|
2004-10-26 02:16:39 +02:00
|
|
|
SetWindowTextW(hWnd, szTitle);
|
2000-07-15 23:35:55 +02:00
|
|
|
SERIALUI_DCBToDialogInfo(hWnd, info);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
{
|
|
|
|
WORD wID = LOWORD(wParam);
|
|
|
|
|
2005-02-15 22:51:06 +01:00
|
|
|
info = (SERIALUI_DialogInfo *) GetWindowLongPtrW(hWnd, DWLP_USER);
|
2000-07-15 23:35:55 +02:00
|
|
|
if(!info)
|
|
|
|
EndDialog(hWnd,0);
|
|
|
|
switch (wID)
|
|
|
|
{
|
|
|
|
case IDOK:
|
|
|
|
SERIALUI_DialogInfoToDCB(hWnd,info);
|
2007-03-06 05:40:56 +01:00
|
|
|
EndDialog(hWnd, ERROR_SUCCESS);
|
2000-07-15 23:35:55 +02:00
|
|
|
return TRUE;
|
|
|
|
case IDCANCEL:
|
2007-03-06 05:40:56 +01:00
|
|
|
EndDialog(hWnd, ERROR_CANCELLED);
|
2000-07-15 23:35:55 +02:00
|
|
|
return TRUE;
|
|
|
|
/* test code for Get/SetDefaultCommConfig begins */
|
|
|
|
case ID_GETDEFAULT:
|
|
|
|
{
|
|
|
|
DWORD r,dwConfSize = sizeof (COMMCONFIG);
|
2004-10-26 02:16:39 +02:00
|
|
|
r = GetDefaultCommConfigW(info->lpszDevice,
|
2000-07-15 23:35:55 +02:00
|
|
|
info->lpCommConfig, &dwConfSize);
|
|
|
|
if(!r)
|
|
|
|
MessageBoxA(hWnd,"Failed","GetDefaultCommConfig",MB_OK);
|
|
|
|
}
|
|
|
|
SERIALUI_DCBToDialogInfo(hWnd, info);
|
|
|
|
break;
|
|
|
|
case ID_SETDEFAULT:
|
|
|
|
{
|
|
|
|
DWORD r;
|
|
|
|
SERIALUI_DialogInfoToDCB(hWnd,info);
|
2004-10-26 02:16:39 +02:00
|
|
|
r = SetDefaultCommConfigW(info->lpszDevice,
|
2000-07-15 23:35:55 +02:00
|
|
|
info->lpCommConfig, sizeof (COMMCONFIG));
|
|
|
|
if(!r)
|
|
|
|
MessageBoxA(hWnd,"Failed","GetDefaultCommConfig",MB_OK);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* test code for Get/SetDefaultCommConfig ends */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-26 02:16:39 +02:00
|
|
|
static LPWSTR SERIALUI_strdup( LPCSTR str )
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
LPWSTR strW;
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
|
|
|
|
strW = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, str, -1, strW, len );
|
|
|
|
return strW;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID SERIALUI_strfree( LPWSTR strW )
|
|
|
|
{
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, strW );
|
2004-10-26 02:16:39 +02:00
|
|
|
}
|
|
|
|
|
2000-07-15 23:35:55 +02:00
|
|
|
/***********************************************************************
|
2004-10-26 02:16:39 +02:00
|
|
|
* drvCommConfigDialogW (SERIALUI.@)
|
2000-07-15 23:35:55 +02:00
|
|
|
*
|
2007-03-06 05:40:56 +01:00
|
|
|
* Show a dialog for configuring a Serial Port.
|
|
|
|
*
|
2000-07-15 23:35:55 +02:00
|
|
|
*/
|
2007-03-06 05:40:56 +01:00
|
|
|
DWORD WINAPI drvCommConfigDialogW(LPCWSTR lpszName, HWND hWndParent, LPCOMMCONFIG lpCommConfig)
|
|
|
|
{
|
2000-07-15 23:35:55 +02:00
|
|
|
SERIALUI_DialogInfo info;
|
2007-03-06 05:40:56 +01:00
|
|
|
INT res;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
info.lpCommConfig = lpCommConfig;
|
|
|
|
info.lpszDevice = lpszName;
|
|
|
|
info.bConvert = FALSE;
|
|
|
|
info.dwFlowControl = 0;
|
|
|
|
|
2007-03-06 05:40:56 +01:00
|
|
|
if ((!lpCommConfig) || (!lpszName))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2007-03-06 05:40:56 +01:00
|
|
|
if (lpCommConfig->dwSize < sizeof(COMMCONFIG))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
if (!lpszName[0])
|
|
|
|
return ERROR_BADKEY;
|
|
|
|
|
|
|
|
res = DialogBoxParamW( SERIALUI_hModule,
|
2004-10-26 02:16:39 +02:00
|
|
|
MAKEINTRESOURCEW(IDD_SERIALUICONFIG),
|
2002-06-01 01:06:46 +02:00
|
|
|
hWndParent,
|
2002-10-31 02:04:39 +01:00
|
|
|
SERIALUI_ConfigDialogProc,
|
2000-07-15 23:35:55 +02:00
|
|
|
(LPARAM)&info);
|
2007-03-06 05:40:56 +01:00
|
|
|
|
|
|
|
return (res == -1) ? GetLastError() : res ;
|
2000-07-15 23:35:55 +02:00
|
|
|
}
|
|
|
|
|
2004-10-26 02:16:39 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* drvCommConfigDialogA (SERIALUI.@)
|
|
|
|
*/
|
2007-03-06 05:40:56 +01:00
|
|
|
DWORD WINAPI drvCommConfigDialogA(LPCSTR lpszName, HWND hWndParent, LPCOMMCONFIG lpCommConfig)
|
2004-10-26 02:16:39 +02:00
|
|
|
{
|
|
|
|
LPWSTR strW = SERIALUI_strdup( lpszName );
|
2007-03-06 05:40:56 +01:00
|
|
|
DWORD r = drvCommConfigDialogW( strW, hWndParent, lpCommConfig );
|
2004-10-26 02:16:39 +02:00
|
|
|
SERIALUI_strfree( strW );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:32:38 +01:00
|
|
|
static const WCHAR lpszCommKey[] = L"System\\CurrentControlSet\\Services\\Class\\Ports";
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2004-10-26 02:16:39 +02:00
|
|
|
* drvSetDefaultCommConfigW (SERIALUI.@)
|
2000-07-15 23:35:55 +02:00
|
|
|
*
|
|
|
|
* Used by Win98 KERNEL to set the default config for a COMM port
|
|
|
|
* FIXME: uses the wrong registry key... should use a digit, not
|
|
|
|
* the comm port name.
|
|
|
|
*/
|
2004-10-26 02:16:39 +02:00
|
|
|
BOOL WINAPI drvSetDefaultCommConfigW(
|
|
|
|
LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, DWORD dwSize)
|
|
|
|
{
|
2000-07-15 23:35:55 +02:00
|
|
|
HKEY hKeyReg=0, hKeyPort=0;
|
2004-10-26 02:16:39 +02:00
|
|
|
WCHAR szKeyName[100];
|
2000-07-15 23:35:55 +02:00
|
|
|
DWORD r,dwDCBSize;
|
|
|
|
|
2006-10-06 23:01:28 +02:00
|
|
|
TRACE("%p %p %x\n",lpszDevice,lpCommConfig,dwSize);
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
if(!lpCommConfig)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if(dwSize < sizeof (COMMCONFIG))
|
|
|
|
return FALSE;
|
|
|
|
|
2004-10-26 02:16:39 +02:00
|
|
|
r = RegConnectRegistryW(NULL, HKEY_LOCAL_MACHINE, &hKeyReg);
|
2000-07-15 23:35:55 +02:00
|
|
|
if(r != ERROR_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-11-03 01:32:38 +01:00
|
|
|
swprintf(szKeyName, ARRAY_SIZE(szKeyName), L"%s\\%s", lpszCommKey, lpszDevice);
|
2004-10-26 02:16:39 +02:00
|
|
|
r = RegCreateKeyW(hKeyReg, szKeyName, &hKeyPort);
|
2000-07-15 23:35:55 +02:00
|
|
|
if(r == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
dwDCBSize = sizeof (DCB);
|
2020-11-03 01:32:38 +01:00
|
|
|
r = RegSetValueExW(hKeyPort, L"DCB", 0, REG_BINARY, (BYTE *)&lpCommConfig->dcb, dwDCBSize);
|
2006-10-06 23:01:28 +02:00
|
|
|
TRACE("write key r=%d\n",r);
|
2000-07-15 23:35:55 +02:00
|
|
|
RegCloseKey(hKeyPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKeyReg);
|
|
|
|
|
|
|
|
return (r==ERROR_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-10-26 02:16:39 +02:00
|
|
|
* drvSetDefaultCommConfigA (SERIALUI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI drvSetDefaultCommConfigA(
|
|
|
|
LPCSTR lpszDevice, LPCOMMCONFIG lpCommConfig, DWORD dwSize)
|
|
|
|
{
|
|
|
|
LPWSTR strW = SERIALUI_strdup( lpszDevice );
|
|
|
|
BOOL r = drvSetDefaultCommConfigW( strW, lpCommConfig, dwSize );
|
|
|
|
SERIALUI_strfree( strW );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* drvGetDefaultCommConfigW (SERIALUI.@)
|
2000-07-15 23:35:55 +02:00
|
|
|
*
|
|
|
|
* Used by Win9x KERNEL to get the default config for a COMM port
|
|
|
|
* FIXME: uses the wrong registry key... should use a digit, not
|
|
|
|
* the comm port name.
|
|
|
|
*/
|
2007-02-22 21:15:23 +01:00
|
|
|
DWORD WINAPI drvGetDefaultCommConfigW(
|
2004-10-26 02:16:39 +02:00
|
|
|
LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, LPDWORD lpdwSize)
|
|
|
|
{
|
2000-07-15 23:35:55 +02:00
|
|
|
HKEY hKeyReg, hKeyPort;
|
2004-10-26 02:16:39 +02:00
|
|
|
WCHAR szKeyName[100];
|
2000-07-15 23:35:55 +02:00
|
|
|
DWORD r,dwSize,dwType;
|
|
|
|
|
2007-02-22 21:15:23 +01:00
|
|
|
TRACE("(%s, %p, %p) *lpdwSize: %u\n", debugstr_w(lpszDevice), lpCommConfig, lpdwSize, lpdwSize ? *lpdwSize : 0);
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2007-02-22 21:15:23 +01:00
|
|
|
if ((!lpszDevice) || (!lpCommConfig) || (!lpdwSize)) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2007-02-22 21:15:23 +01:00
|
|
|
if (*lpdwSize < sizeof (COMMCONFIG)) {
|
|
|
|
*lpdwSize = sizeof (COMMCONFIG);
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2007-02-22 21:15:23 +01:00
|
|
|
/* only "com1" - "com9" is allowed */
|
2020-11-03 01:32:38 +01:00
|
|
|
r = ARRAY_SIZE(L"com");
|
2007-02-22 21:15:23 +01:00
|
|
|
lstrcpynW(szKeyName, lpszDevice, r); /* simulate a lstrcmpnW */
|
|
|
|
r--;
|
2007-03-06 05:40:56 +01:00
|
|
|
|
2020-11-03 01:32:38 +01:00
|
|
|
if (lstrcmpiW(szKeyName, L"com") ||
|
2007-02-22 21:15:23 +01:00
|
|
|
(lpszDevice[r] < '1') || (lpszDevice[r] > '9') || lpszDevice[r+1]) {
|
|
|
|
return ERROR_BADKEY;
|
|
|
|
}
|
2000-07-15 23:35:55 +02:00
|
|
|
|
|
|
|
*lpdwSize = sizeof (COMMCONFIG);
|
|
|
|
memset(lpCommConfig, 0 , sizeof (COMMCONFIG));
|
|
|
|
lpCommConfig->dwSize = sizeof (COMMCONFIG);
|
|
|
|
lpCommConfig->wVersion = 1;
|
2007-02-26 22:14:46 +01:00
|
|
|
lpCommConfig->dwProviderSubType = PST_RS232;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2004-10-26 02:16:39 +02:00
|
|
|
r = RegConnectRegistryW(NULL, HKEY_LOCAL_MACHINE, &hKeyReg);
|
2007-02-22 21:15:23 +01:00
|
|
|
if(r != ERROR_SUCCESS) return r;
|
2000-07-15 23:35:55 +02:00
|
|
|
|
2020-11-03 01:32:38 +01:00
|
|
|
swprintf(szKeyName, ARRAY_SIZE(szKeyName), L"%s\\%s", lpszCommKey, lpszDevice);
|
2004-10-26 02:16:39 +02:00
|
|
|
r = RegOpenKeyW(hKeyReg, szKeyName, &hKeyPort);
|
2000-07-15 23:35:55 +02:00
|
|
|
if(r == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
dwSize = sizeof (DCB);
|
|
|
|
dwType = 0;
|
2020-11-03 01:32:38 +01:00
|
|
|
r = RegQueryValueExW(hKeyPort, L"DCB", NULL, &dwType, (BYTE *)&lpCommConfig->dcb, &dwSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 23:35:55 +02:00
|
|
|
RegCloseKey(hKeyPort);
|
2007-02-22 21:15:23 +01:00
|
|
|
if ((r!=ERROR_SUCCESS) || (dwType != REG_BINARY) || (dwSize != sizeof(DCB))) {
|
|
|
|
RegCloseKey(hKeyReg);
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2000-07-15 23:35:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: default to a hardcoded commconfig */
|
|
|
|
lpCommConfig->dcb.DCBlength = sizeof(DCB);
|
|
|
|
lpCommConfig->dcb.BaudRate = 9600;
|
|
|
|
lpCommConfig->dcb.fBinary = TRUE;
|
|
|
|
lpCommConfig->dcb.fParity = FALSE;
|
|
|
|
lpCommConfig->dcb.ByteSize = 8;
|
|
|
|
lpCommConfig->dcb.Parity = NOPARITY;
|
|
|
|
lpCommConfig->dcb.StopBits = ONESTOPBIT;
|
2007-02-22 21:15:23 +01:00
|
|
|
return ERROR_SUCCESS;
|
2000-07-15 23:35:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKeyReg);
|
|
|
|
|
2007-02-22 21:15:23 +01:00
|
|
|
return r;
|
2000-07-15 23:35:55 +02:00
|
|
|
}
|
2004-10-26 02:16:39 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* drvGetDefaultCommConfigA (SERIALUI.@)
|
|
|
|
*/
|
2007-02-22 21:15:23 +01:00
|
|
|
DWORD WINAPI drvGetDefaultCommConfigA(
|
2004-10-26 02:16:39 +02:00
|
|
|
LPCSTR lpszDevice, LPCOMMCONFIG lpCommConfig, LPDWORD lpdwSize)
|
|
|
|
{
|
|
|
|
LPWSTR strW = SERIALUI_strdup( lpszDevice );
|
2007-02-22 21:15:23 +01:00
|
|
|
DWORD r = drvGetDefaultCommConfigW( strW, lpCommConfig, lpdwSize );
|
2004-10-26 02:16:39 +02:00
|
|
|
SERIALUI_strfree( strW );
|
|
|
|
return r;
|
|
|
|
}
|