ReactOS  0.4.15-dev-1203-g0e5a4d5
serial.c File Reference
#include "precomp.h"
Include dependency graph for serial.c:

Go to the source code of this file.

Classes

struct  _PORT_DATA
 

Macros

#define DEFAULT_BAUD_RATE_INDEX   11
 
#define DEFAULT_DATA_BITS_INDEX   4
 
#define DEFAULT_PARITY_INDEX   2
 
#define DEFAULT_STOP_BITS_INDEX   0
 
#define DEFAULT_FLOW_CONTROL_INDEX   2
 

Typedefs

typedef struct _PORT_DATA PORT_DATA
 
typedef struct _PORT_DATAPPORT_DATA
 

Functions

static VOID FillComboBox (HWND hwnd, PWSTR szBuffer)
 
static VOID ReadPortSettings (PPORT_DATA pPortData)
 
static VOID WritePortSettings (HWND hwnd, PPORT_DATA pPortData)
 
static BOOL OnInitDialog (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
static VOID RestoreDefaultValues (HWND hwnd, PPORT_DATA pPortData)
 
static VOID OnCommand (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
static VOID OnNotify (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
static VOID OnDestroy (HWND hwnd)
 
static INT_PTR CALLBACK SerialSettingsDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
BOOL WINAPI SerialPortPropPageProvider (PSP_PROPSHEETPAGE_REQUEST lpPropSheetPageRequest, LPFNADDPROPSHEETPAGE lpfnAddPropSheetPageProc, LPARAM lParam)
 

Variables

DWORD BaudRates []
 
PWSTR Paritys [] = {L"e", L"o", L"n", L"m", L"s"}
 
PWSTR DataBits [] = {L"4", L"5", L"6", L"7", L"8"}
 
PWSTR StopBits [] = {L"1", L"1.5", L"2"}
 
PWSTR FlowControls [] = {L"x", L"p"}
 

Macro Definition Documentation

◆ DEFAULT_BAUD_RATE_INDEX

#define DEFAULT_BAUD_RATE_INDEX   11

Definition at line 27 of file serial.c.

◆ DEFAULT_DATA_BITS_INDEX

#define DEFAULT_DATA_BITS_INDEX   4

Definition at line 28 of file serial.c.

◆ DEFAULT_FLOW_CONTROL_INDEX

#define DEFAULT_FLOW_CONTROL_INDEX   2

Definition at line 31 of file serial.c.

◆ DEFAULT_PARITY_INDEX

#define DEFAULT_PARITY_INDEX   2

Definition at line 29 of file serial.c.

◆ DEFAULT_STOP_BITS_INDEX

#define DEFAULT_STOP_BITS_INDEX   0

Definition at line 30 of file serial.c.

Typedef Documentation

◆ PORT_DATA

◆ PPORT_DATA

Function Documentation

◆ FillComboBox()

static VOID FillComboBox ( HWND  hwnd,
PWSTR  szBuffer 
)
static

Definition at line 43 of file serial.c.

46 {
47  PWSTR pStart, pEnd;
48 
49  pStart = szBuffer;
50  for (;;)
51  {
52  pEnd = wcschr(pStart, L',');
53  if (pEnd != NULL)
54  *pEnd = UNICODE_NULL;
55 
56  ComboBox_AddString(hwnd, pStart);
57 
58  if (pEnd == NULL)
59  break;
60 
61  pStart = pEnd + 1;
62  }
63 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define ComboBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:16
uint16_t * PWSTR
Definition: typedefs.h:56
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
static const WCHAR L[]
Definition: oid.c:1250

Referenced by OnInitDialog().

◆ OnCommand()

static VOID OnCommand ( HWND  hwnd,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 491 of file serial.c.

495 {
496  PPORT_DATA pPortData;
497 
498  TRACE("OnCommand()\n");
499 
500  pPortData = (PPORT_DATA)GetWindowLongPtr(hwnd, DWLP_USER);
501  if (pPortData == NULL)
502  {
503  ERR("pPortData is NULL\n");
504  return;
505  }
506 
507  switch (LOWORD(wParam))
508  {
510  case IDC_SERIAL_DATABITS:
511  case IDC_SERIAL_PARITY:
512  case IDC_SERIAL_STOPBITS:
514  if (HIWORD(wParam) == CBN_SELCHANGE ||
516  {
517  pPortData->bChanged = TRUE;
518  }
519  break;
520 
521 // case IDC_SERIAL_ADVANCED:
522 
523  case IDC_SERIAL_RESTORE:
524  RestoreDefaultValues(hwnd, pPortData);
525  break;
526 
527  default:
528  break;
529  }
530 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
struct _PORT_DATA * PPORT_DATA
#define IDC_SERIAL_DATABITS
Definition: resource.h:5
#define TRUE
Definition: types.h:120
WPARAM wParam
Definition: combotst.c:138
static VOID RestoreDefaultValues(HWND hwnd, PPORT_DATA pPortData)
Definition: serial.c:444
#define IDC_SERIAL_PARITY
Definition: resource.h:6
#define IDC_SERIAL_STOPBITS
Definition: resource.h:7
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define CBN_EDITCHANGE
Definition: winuser.h:1957
#define IDC_SERIAL_RESTORE
Definition: resource.h:10
#define IDC_SERIAL_FLOWCONTROL
Definition: resource.h:8
#define DWLP_USER
Definition: winuser.h:866
#define ERR(fmt,...)
Definition: debug.h:110
#define CBN_SELCHANGE
Definition: winuser.h:1961
#define HIWORD(l)
Definition: typedefs.h:247
#define IDC_SERIAL_BITSPERSECOND
Definition: resource.h:4
BOOL bChanged
Definition: serial.c:24
#define GetWindowLongPtr
Definition: treelist.c:73
#define LOWORD(l)
Definition: pedump.c:82

Referenced by SerialSettingsDlgProc().

◆ OnDestroy()

static VOID OnDestroy ( HWND  hwnd)
static

Definition at line 561 of file serial.c.

563 {
564  PPORT_DATA pPortData;
565 
566  TRACE("OnDestroy()\n");
567 
568  pPortData = (PPORT_DATA)GetWindowLongPtr(hwnd, DWLP_USER);
569  if (pPortData == NULL)
570  {
571  ERR("pPortData is NULL\n");
572  return;
573  }
574 
575  HeapFree(GetProcessHeap(), 0, pPortData);
577 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
struct _PORT_DATA * PPORT_DATA
#define SetWindowLongPtr
Definition: treelist.c:70
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
#define DWLP_USER
Definition: winuser.h:866
#define ERR(fmt,...)
Definition: debug.h:110
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GetWindowLongPtr
Definition: treelist.c:73
#define HeapFree(x, y, z)
Definition: compat.h:594

Referenced by SerialSettingsDlgProc().

◆ OnInitDialog()

static BOOL OnInitDialog ( HWND  hwnd,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 354 of file serial.c.

358 {
359  PPORT_DATA pPortData;
360  WCHAR szBuffer[256];
361  UINT i;
362  HWND hwndControl;
363 
364  TRACE("OnInitDialog()\n");
365 
366  pPortData = (PPORT_DATA)((LPPROPSHEETPAGEW)lParam)->lParam;
367  if (pPortData == NULL)
368  {
369  ERR("pPortData is NULL\n");
370  return FALSE;
371  }
372 
373  SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)pPortData);
374 
375  /* Read and parse the port settings */
376  ReadPortSettings(pPortData);
377 
378  /* Fill the 'Bits per second' combobox */
379  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_BITSPERSECOND);
380  if (hwndControl)
381  {
382  for (i = 0; i < ARRAYSIZE(BaudRates); i++)
383  {
384  _ultow(BaudRates[i], szBuffer, 10);
385  ComboBox_AddString(hwndControl, szBuffer);
386  }
387 
388  ComboBox_SetCurSel(hwndControl, pPortData->nBaudRateIndex);
389  }
390 
391  /* Fill the 'Data bits' combobox */
392  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_DATABITS);
393  if (hwndControl)
394  {
395  for (i = 0; i < ARRAYSIZE(DataBits); i++)
396  {
397  ComboBox_AddString(hwndControl, DataBits[i]);
398  }
399 
400  ComboBox_SetCurSel(hwndControl, pPortData->nDataBitsIndex);
401  }
402 
403  /* Fill the 'Parity' combobox */
404  LoadStringW(hInstance, IDS_PARITY, szBuffer, ARRAYSIZE(szBuffer));
405 
406  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_PARITY);
407  if (hwndControl)
408  {
409  FillComboBox(hwndControl, szBuffer);
410  ComboBox_SetCurSel(hwndControl, pPortData->nParityIndex);
411  }
412 
413  /* Fill the 'Stop bits' combobox */
414  LoadStringW(hInstance, IDS_STOPBITS, szBuffer, ARRAYSIZE(szBuffer));
415 
416  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_STOPBITS);
417  if (hwndControl)
418  {
419  FillComboBox(hwndControl, szBuffer);
420  ComboBox_SetCurSel(hwndControl, pPortData->nStopBitsIndex);
421  }
422 
423  /* Fill the 'Flow control' combobox */
424  LoadStringW(hInstance, IDS_FLOWCONTROL, szBuffer, ARRAYSIZE(szBuffer));
425 
426  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_FLOWCONTROL);
427  if (hwndControl)
428  {
429  FillComboBox(hwndControl, szBuffer);
430  ComboBox_SetCurSel(hwndControl, pPortData->nFlowControlIndex);
431  }
432 
433  /* Disable the 'Advanced' button */
434  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_ADVANCED);
435  if (hwndControl)
436  EnableWindow(hwndControl, FALSE);
437 
438  return TRUE;
439 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
_CRTIMP wchar_t *__cdecl _ultow(_In_ unsigned long _Value, _Pre_notnull_ _Post_z_ wchar_t *_Dest, _In_ int _Radix)
struct _PORT_DATA * PPORT_DATA
#define ComboBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:16
#define IDC_SERIAL_DATABITS
Definition: resource.h:5
#define IDS_STOPBITS
Definition: resource.h:21
#define TRUE
Definition: types.h:120
PWSTR DataBits[]
Definition: serial.c:36
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define SetWindowLongPtr
Definition: treelist.c:70
INT nParityIndex
Definition: serial.c:19
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE hInstance
Definition: charmap.c:20
#define FALSE
Definition: types.h:117
#define IDC_SERIAL_PARITY
Definition: resource.h:6
#define IDC_SERIAL_STOPBITS
Definition: resource.h:7
static VOID ReadPortSettings(PPORT_DATA pPortData)
Definition: serial.c:68
#define IDC_SERIAL_ADVANCED
Definition: resource.h:9
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define IDS_PARITY
Definition: resource.h:20
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
INT nStopBitsIndex
Definition: serial.c:21
INT nDataBitsIndex
Definition: serial.c:20
#define IDC_SERIAL_FLOWCONTROL
Definition: resource.h:8
#define DWLP_USER
Definition: winuser.h:866
DWORD BaudRates[]
Definition: serial.c:33
#define ComboBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:41
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define ERR(fmt,...)
Definition: debug.h:110
INT nFlowControlIndex
Definition: serial.c:22
static VOID FillComboBox(HWND hwnd, PWSTR szBuffer)
Definition: serial.c:43
#define IDS_FLOWCONTROL
Definition: resource.h:22
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define IDC_SERIAL_BITSPERSECOND
Definition: resource.h:4
INT nBaudRateIndex
Definition: serial.c:18
LPARAM lParam
Definition: combotst.c:139

Referenced by SerialSettingsDlgProc().

◆ OnNotify()

static VOID OnNotify ( HWND  hwnd,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 535 of file serial.c.

539 {
540  PPORT_DATA pPortData;
541 
542  TRACE("OnCommand()\n");
543 
544  pPortData = (PPORT_DATA)GetWindowLongPtr(hwnd, DWLP_USER);
545  if (pPortData == NULL)
546  {
547  ERR("pPortData is NULL\n");
548  return;
549  }
550 
551  if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY)
552  {
553  FIXME("PSN_APPLY!\n");
554  WritePortSettings(hwnd, pPortData);
555  }
556 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
struct _PORT_DATA * PPORT_DATA
#define PSN_APPLY
Definition: prsht.h:117
#define FIXME(fmt,...)
Definition: debug.h:111
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static VOID WritePortSettings(HWND hwnd, PPORT_DATA pPortData)
Definition: serial.c:228
#define DWLP_USER
Definition: winuser.h:866
Definition: inflate.c:139
#define ERR(fmt,...)
Definition: debug.h:110
unsigned int UINT
Definition: ndis.h:50
#define GetWindowLongPtr
Definition: treelist.c:73
LPARAM lParam
Definition: combotst.c:139

Referenced by SerialSettingsDlgProc().

◆ ReadPortSettings()

static VOID ReadPortSettings ( PPORT_DATA  pPortData)
static

Definition at line 68 of file serial.c.

70 {
71  WCHAR szPortData[32];
72  WCHAR szParity[4];
73  WCHAR szDataBits[4];
74  WCHAR szStopBits[4];
75  WCHAR szFlowControl[4];
76  DWORD dwType, dwSize;
77  DWORD dwBaudRate = 0;
78  HKEY hKey;
79  INT n, i;
80  LONG lError;
81 
82  TRACE("ReadPortSettings(%p)\n", pPortData);
83 
84  pPortData->nBaudRateIndex = DEFAULT_BAUD_RATE_INDEX; /* 9600 */
85  pPortData->nParityIndex = DEFAULT_PARITY_INDEX; /* None */
86  pPortData->nDataBitsIndex = DEFAULT_DATA_BITS_INDEX; /* 8 Data Bits */
87  pPortData->nStopBitsIndex = DEFAULT_STOP_BITS_INDEX; /* 1 Stop Bit */
88  pPortData->nFlowControlIndex = DEFAULT_FLOW_CONTROL_INDEX; /* None */
89  pPortData->bChanged = FALSE;
90 
91  hKey = SetupDiOpenDevRegKey(pPortData->DeviceInfoSet,
92  pPortData->DeviceInfoData,
94  0,
95  DIREG_DEV,
96  KEY_READ);
97  if (hKey == INVALID_HANDLE_VALUE)
98  {
99  ERR("SetupDiOpenDevRegKey() failed\n");
100  return;
101  }
102 
103  dwSize = sizeof(pPortData->szPortName);
104  lError = RegQueryValueExW(hKey,
105  L"PortName",
106  NULL,
107  NULL,
108  (PBYTE)pPortData->szPortName,
109  &dwSize);
110  RegCloseKey(hKey);
111 
112  if (lError != ERROR_SUCCESS)
113  {
114  ERR("RegQueryValueExW failed (Error %lu)\n", lError);
115  return;
116  }
117 
118  wcscat(pPortData->szPortName, L":");
119  TRACE("PortName: '%S'\n", pPortData->szPortName);
120 
122  L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports",
123  0,
124  KEY_READ,
125  &hKey);
126  if (lError != ERROR_SUCCESS)
127  {
128  ERR("RegOpenKeyExW failed (Error %lu)\n", lError);
129  return;
130  }
131 
132  dwSize = sizeof(szPortData);
133  lError = RegQueryValueExW(hKey,
134  pPortData->szPortName,
135  NULL,
136  &dwType,
137  (LPBYTE)szPortData,
138  &dwSize);
139  RegCloseKey(hKey);
140 
141  if (lError != ERROR_SUCCESS)
142  {
143  ERR("RegQueryValueExW failed (Error %lu)\n", lError);
144  return;
145  }
146 
147  if ((dwType != REG_SZ) || (dwSize > sizeof(szPortData)))
148  {
149  ERR("Wrong type or size\n");
150  return;
151  }
152 
153  TRACE("szPortData: '%S'\n", szPortData);
154 
155  /* Replace commas by spaces */
156  for (i = 0; i < wcslen(szPortData); i++)
157  {
158  if (szPortData[i] == L',')
159  szPortData[i] = L' ';
160  }
161 
162  TRACE("szPortData: '%S'\n", szPortData);
163 
164  /* Parse the port settings */
165  n = swscanf(szPortData,
166  L"%lu %3s %3s %3s %3s",
167  &dwBaudRate,
168  &szParity,
169  &szDataBits,
170  &szStopBits,
171  &szFlowControl);
172 
173  TRACE("dwBaudRate: %lu\n", dwBaudRate);
174  TRACE("szParity: '%S'\n", szParity);
175  TRACE("szDataBits: '%S'\n", szDataBits);
176  TRACE("szStopBits: '%S'\n", szStopBits);
177  TRACE("szFlowControl: '%S'\n", szFlowControl);
178 
179  if (n > 0)
180  {
181  for (i = 0; i < ARRAYSIZE(BaudRates); i++)
182  {
183  if (dwBaudRate == BaudRates[i])
184  pPortData->nBaudRateIndex = i;
185  }
186  }
187 
188  if (n > 1)
189  {
190  for (i = 0; i < ARRAYSIZE(Paritys); i++)
191  {
192  if (_wcsicmp(szParity, Paritys[i]) == 0)
193  pPortData->nParityIndex = i;
194  }
195  }
196 
197  if (n > 2)
198  {
199  for (i = 0; i < ARRAYSIZE(DataBits); i++)
200  {
201  if (_wcsicmp(szDataBits, DataBits[i]) == 0)
202  pPortData->nDataBitsIndex = i;
203  }
204  }
205 
206  if (n > 3)
207  {
208  for (i = 0; i < ARRAYSIZE(StopBits); i++)
209  {
210  if (_wcsicmp(szStopBits, StopBits[i]) == 0)
211  pPortData->nStopBitsIndex = i;
212  }
213  }
214 
215  if (n > 4)
216  {
217  for (i = 0; i < ARRAYSIZE(FlowControls); i++)
218  {
219  if (_wcsicmp(szFlowControl, FlowControls[i]) == 0)
220  pPortData->nFlowControlIndex = i;
221  }
222  }
223 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
GLdouble n
Definition: glext.h:7729
PWSTR DataBits[]
Definition: serial.c:36
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
WCHAR szPortName[16]
Definition: parallel.c:17
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
PWSTR FlowControls[]
Definition: serial.c:38
#define DEFAULT_STOP_BITS_INDEX
Definition: serial.c:30
int32_t INT
Definition: typedefs.h:58
PWSTR StopBits[]
Definition: serial.c:37
INT nParityIndex
Definition: serial.c:19
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define DEFAULT_DATA_BITS_INDEX
Definition: serial.c:28
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define DIREG_DEV
Definition: setupapi.h:181
unsigned long DWORD
Definition: ntddk_ex.h:95
INT nStopBitsIndex
Definition: serial.c:21
INT nDataBitsIndex
Definition: serial.c:20
PWSTR Paritys[]
Definition: serial.c:35
static const WCHAR L[]
Definition: oid.c:1250
DWORD BaudRates[]
Definition: serial.c:33
HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired)
Definition: devinst.c:5935
#define ERR(fmt,...)
Definition: debug.h:110
#define DICS_FLAG_GLOBAL
Definition: setupapi.h:113
INT nFlowControlIndex
Definition: serial.c:22
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
HDEVINFO DeviceInfoSet
Definition: parallel.c:14
PSP_DEVINFO_DATA DeviceInfoData
Definition: parallel.c:15
#define DEFAULT_PARITY_INDEX
Definition: serial.c:29
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define DEFAULT_BAUD_RATE_INDEX
Definition: serial.c:27
BOOL bChanged
Definition: serial.c:24
INT nBaudRateIndex
Definition: serial.c:18
#define DEFAULT_FLOW_CONTROL_INDEX
Definition: serial.c:31
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
BYTE * PBYTE
Definition: pedump.c:66
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by OnInitDialog().

◆ RestoreDefaultValues()

static VOID RestoreDefaultValues ( HWND  hwnd,
PPORT_DATA  pPortData 
)
static

Definition at line 444 of file serial.c.

447 {
448  HWND hwndControl;
449 
450  /* Reset the 'Bits per second' combobox */
451  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_BITSPERSECOND);
452  if (hwndControl)
453  {
455  }
456 
457  /* Reset the 'Data bits' combobox */
458  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_DATABITS);
459  if (hwndControl)
460  {
462  }
463 
464  /* Reset the 'Parity' combobox */
465  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_PARITY);
466  if (hwndControl)
467  {
469  }
470 
471  /* Reset the 'Stop bits' combobox */
472  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_STOPBITS);
473  if (hwndControl)
474  {
476  }
477 
478  /* Reset the 'Flow control' combobox */
479  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_FLOWCONTROL);
480  if (hwndControl)
481  {
483  }
484 
485  pPortData->bChanged = TRUE;
486 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDC_SERIAL_DATABITS
Definition: resource.h:5
#define TRUE
Definition: types.h:120
#define DEFAULT_STOP_BITS_INDEX
Definition: serial.c:30
#define IDC_SERIAL_PARITY
Definition: resource.h:6
#define IDC_SERIAL_STOPBITS
Definition: resource.h:7
#define DEFAULT_DATA_BITS_INDEX
Definition: serial.c:28
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDC_SERIAL_FLOWCONTROL
Definition: resource.h:8
#define ComboBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:41
#define DEFAULT_PARITY_INDEX
Definition: serial.c:29
#define DEFAULT_BAUD_RATE_INDEX
Definition: serial.c:27
#define IDC_SERIAL_BITSPERSECOND
Definition: resource.h:4
BOOL bChanged
Definition: serial.c:24
#define DEFAULT_FLOW_CONTROL_INDEX
Definition: serial.c:31

Referenced by OnCommand().

◆ SerialPortPropPageProvider()

BOOL WINAPI SerialPortPropPageProvider ( PSP_PROPSHEETPAGE_REQUEST  lpPropSheetPageRequest,
LPFNADDPROPSHEETPAGE  lpfnAddPropSheetPageProc,
LPARAM  lParam 
)

Definition at line 614 of file serial.c.

618 {
620  HPROPSHEETPAGE hPropSheetPage;
621  PPORT_DATA pPortData;
622 
623  TRACE("SerialPortPropPageProvider(%p %p %lx)\n",
624  lpPropSheetPageRequest, lpfnAddPropSheetPageProc, lParam);
625 
626  pPortData = HeapAlloc(GetProcessHeap(),
628  sizeof(PORT_DATA));
629  if (pPortData == NULL)
630  {
631  ERR("Port data allocation failed!\n");
632  return FALSE;
633  }
634 
635  pPortData->DeviceInfoSet = lpPropSheetPageRequest->DeviceInfoSet;
636  pPortData->DeviceInfoData = lpPropSheetPageRequest->DeviceInfoData;
637 
638  if (lpPropSheetPageRequest->PageRequested == SPPSR_ENUM_ADV_DEVICE_PROPERTIES)
639  {
640  TRACE("SPPSR_ENUM_ADV_DEVICE_PROPERTIES\n");
641 
642  PropSheetPage.dwSize = sizeof(PROPSHEETPAGEW);
643  PropSheetPage.dwFlags = 0;
644  PropSheetPage.hInstance = hInstance;
647  PropSheetPage.lParam = (LPARAM)pPortData;
648  PropSheetPage.pfnCallback = NULL;
649 
650  hPropSheetPage = CreatePropertySheetPageW(&PropSheetPage);
651  if (hPropSheetPage == NULL)
652  {
653  ERR("CreatePropertySheetPageW() failed!\n");
654  return FALSE;
655  }
656 
657  if (!(*lpfnAddPropSheetPageProc)(hPropSheetPage, lParam))
658  {
659  ERR("lpfnAddPropSheetPageProc() failed!\n");
660  DestroyPropertySheetPage(hPropSheetPage);
661  return FALSE;
662  }
663  }
664 
665  TRACE("Done!\n");
666 
667  return TRUE;
668 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define TRUE
Definition: types.h:120
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
Definition: propsheet.c:3144
HINSTANCE hInstance
Definition: charmap.c:20
PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1099
#define FALSE
Definition: types.h:117
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
struct _PROPSHEETPAGEW PROPSHEETPAGEW
smooth NULL
Definition: ftsmooth.c:416
static INT_PTR CALLBACK SerialSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: serial.c:583
LONG_PTR LPARAM
Definition: windef.h:208
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
Definition: propsheet.c:3075
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define IDD_SERIALSETTINGS
Definition: resource.h:3
#define SPPSR_ENUM_ADV_DEVICE_PROPERTIES
Definition: setupapi.h:610
#define ERR(fmt,...)
Definition: debug.h:110
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HDEVINFO DeviceInfoSet
Definition: parallel.c:14
PSP_DEVINFO_DATA DeviceInfoData
Definition: parallel.c:15
LPARAM lParam
Definition: combotst.c:139

◆ SerialSettingsDlgProc()

static INT_PTR CALLBACK SerialSettingsDlgProc ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 583 of file serial.c.

587 {
588  TRACE("SerialSettingsDlgProc()\n");
589 
590  switch (uMsg)
591  {
592  case WM_INITDIALOG:
593  return OnInitDialog(hwnd, wParam, lParam);
594 
595  case WM_COMMAND:
597  break;
598 
599  case WM_NOTIFY:
601  break;
602 
603  case WM_DESTROY:
604  OnDestroy(hwnd);
605  break;
606  }
607 
608  return FALSE;
609 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
static BOOL OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: serial.c:354
static VOID OnNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: serial.c:535
WPARAM wParam
Definition: combotst.c:138
#define FALSE
Definition: types.h:117
#define WM_DESTROY
Definition: winuser.h:1591
#define TRACE(s)
Definition: solgame.cpp:4
#define WM_COMMAND
Definition: winuser.h:1722
static VOID OnDestroy(HWND hwnd)
Definition: serial.c:561
static VOID OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: serial.c:491
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define WM_NOTIFY
Definition: richedit.h:61

Referenced by SerialPortPropPageProvider().

◆ WritePortSettings()

static VOID WritePortSettings ( HWND  hwnd,
PPORT_DATA  pPortData 
)
static

Definition at line 228 of file serial.c.

231 {
232  SP_PROPCHANGE_PARAMS PropChangeParams;
233  WCHAR szPortData[32];
234  HWND hwndControl;
235  INT nBaudRateIndex;
236  INT nDataBitsIndex;
237  INT nParityIndex;
238  INT nStopBitsIndex;
239  INT nFlowControlIndex;
240  HKEY hKey;
241  LONG lError;
242 
243  TRACE("WritePortSettings(%p)\n", pPortData);
244 
245  if (pPortData->bChanged == FALSE)
246  {
247  TRACE("Nothing changed. Done!\n");
248  return;
249  }
250 
251  nBaudRateIndex = pPortData->nBaudRateIndex;
252  nDataBitsIndex = pPortData->nDataBitsIndex;
253  nParityIndex = pPortData->nParityIndex;
254  nStopBitsIndex = pPortData->nStopBitsIndex;
255  nFlowControlIndex = pPortData->nFlowControlIndex;
256 
257  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_BITSPERSECOND);
258  if (hwndControl)
259  {
260  nBaudRateIndex = ComboBox_GetCurSel(hwndControl);
261  }
262 
263  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_DATABITS);
264  if (hwndControl)
265  {
266  nDataBitsIndex = ComboBox_GetCurSel(hwndControl);
267  }
268 
269  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_PARITY);
270  if (hwndControl)
271  {
272  nParityIndex = ComboBox_GetCurSel(hwndControl);
273  }
274 
275  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_STOPBITS);
276  if (hwndControl)
277  {
278  nStopBitsIndex = ComboBox_GetCurSel(hwndControl);
279  }
280 
281  hwndControl = GetDlgItem(hwnd, IDC_SERIAL_FLOWCONTROL);
282  if (hwndControl)
283  {
284  nFlowControlIndex = ComboBox_GetCurSel(hwndControl);
285  }
286 
287  swprintf(szPortData,
288  L"%lu,%s,%s,%s",
289  BaudRates[nBaudRateIndex],
290  Paritys[nParityIndex],
291  DataBits[nDataBitsIndex],
292  StopBits[nStopBitsIndex]);
293  if (nFlowControlIndex < 2)
294  {
295  wcscat(szPortData, L",");
296  wcscat(szPortData, FlowControls[nFlowControlIndex]);
297  }
298 
299  TRACE("szPortData: '%S'\n", szPortData);
300 
302  L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports",
303  0,
304  KEY_WRITE,
305  &hKey);
306  if (lError != ERROR_SUCCESS)
307  {
308  ERR("RegOpenKeyExW failed (Error %lu)\n", lError);
309  return;
310  }
311 
312  lError = RegSetValueExW(hKey,
313  pPortData->szPortName,
314  0,
315  REG_SZ,
316  (LPBYTE)szPortData,
317  (wcslen(szPortData) + 1) * sizeof(WCHAR));
318 
319  RegCloseKey(hKey);
320 
321  if (lError != ERROR_SUCCESS)
322  {
323  ERR("RegSetValueExW failed (Error %lu)\n", lError);
324  return;
325  }
326 
327  /* Notify the system */
330  0,
331  (LPARAM)pPortData->szPortName);
332 
333  /* Notify the installer (and device) */
334  PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
336  PropChangeParams.Scope = DICS_FLAG_GLOBAL;
337  PropChangeParams.StateChange = DICS_PROPCHANGE;
338 
340  pPortData->DeviceInfoData,
341  (PSP_CLASSINSTALL_HEADER)&PropChangeParams,
342  sizeof(SP_PROPCHANGE_PARAMS));
343 
345  pPortData->DeviceInfoSet,
346  pPortData->DeviceInfoData);
347 
348  TRACE("Done!\n");
349 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IDC_SERIAL_DATABITS
Definition: resource.h:5
PWSTR DataBits[]
Definition: serial.c:36
WCHAR szPortName[16]
Definition: parallel.c:17
#define ComboBox_GetCurSel(hwndCtl)
Definition: windowsx.h:24
PWSTR FlowControls[]
Definition: serial.c:38
BOOL WINAPI SetupDiCallClassInstaller(DI_FUNCTION InstallFunction, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:4029
#define DIF_PROPERTYCHANGE
Definition: setupapi.h:137
int32_t INT
Definition: typedefs.h:58
PWSTR StopBits[]
Definition: serial.c:37
INT nParityIndex
Definition: serial.c:19
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define IDC_SERIAL_PARITY
Definition: resource.h:6
#define IDC_SERIAL_STOPBITS
Definition: resource.h:7
#define WM_WININICHANGE
Definition: winuser.h:1612
LONG_PTR LPARAM
Definition: windef.h:208
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
SP_CLASSINSTALL_HEADER ClassInstallHeader
Definition: setupapi.h:911
#define TRACE(s)
Definition: solgame.cpp:4
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
INT nStopBitsIndex
Definition: serial.c:21
INT nDataBitsIndex
Definition: serial.c:20
PWSTR Paritys[]
Definition: serial.c:35
#define IDC_SERIAL_FLOWCONTROL
Definition: resource.h:8
static const WCHAR L[]
Definition: oid.c:1250
DWORD BaudRates[]
Definition: serial.c:33
#define ERR(fmt,...)
Definition: debug.h:110
#define DICS_FLAG_GLOBAL
Definition: setupapi.h:113
#define DICS_PROPCHANGE
Definition: setupapi.h:116
INT nFlowControlIndex
Definition: serial.c:22
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
HDEVINFO DeviceInfoSet
Definition: parallel.c:14
PSP_DEVINFO_DATA DeviceInfoData
Definition: parallel.c:15
struct _SP_CLASSINSTALL_HEADER SP_CLASSINSTALL_HEADER
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define IDC_SERIAL_BITSPERSECOND
Definition: resource.h:4
BOOL bChanged
Definition: serial.c:24
#define SetupDiSetClassInstallParams
Definition: setupapi.h:2612
INT nBaudRateIndex
Definition: serial.c:18
#define HWND_BROADCAST
Definition: winuser.h:1190
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
DI_FUNCTION InstallFunction
Definition: setupapi.h:899
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by OnNotify().

Variable Documentation

◆ BaudRates

DWORD BaudRates[]
Initial value:
= {75, 110, 134, 150, 300, 600, 1200, 1800, 2400, 4800,
7200, 9600, 14400, 19200, 38400, 57600, 115200, 128000}

Definition at line 33 of file serial.c.

Referenced by OnInitDialog(), ReadPortSettings(), and WritePortSettings().

◆ DataBits

PWSTR DataBits[] = {L"4", L"5", L"6", L"7", L"8"}

Definition at line 36 of file serial.c.

Referenced by OnInitDialog(), ReadPortSettings(), and WritePortSettings().

◆ FlowControls

PWSTR FlowControls[] = {L"x", L"p"}

Definition at line 38 of file serial.c.

Referenced by ReadPortSettings(), and WritePortSettings().

◆ Paritys

PWSTR Paritys[] = {L"e", L"o", L"n", L"m", L"s"}

Definition at line 35 of file serial.c.

Referenced by ReadPortSettings(), and WritePortSettings().

◆ StopBits

PWSTR StopBits[] = {L"1", L"1.5", L"2"}

Definition at line 37 of file serial.c.

Referenced by check_dcb(), ParseStopBits(), ReadPortSettings(), test_pack_DCB(), and WritePortSettings().