ReactOS 0.4.15-dev-7942-gd23573b
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}
#define NULL
Definition: types.h:112
#define wcschr
Definition: compat.h:17
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
uint16_t * PWSTR
Definition: typedefs.h:56
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define ComboBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:41

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
501 if (pPortData == NULL)
502 {
503 ERR("pPortData is NULL\n");
504 return;
505 }
506
507 switch (LOWORD(wParam))
508 {
514 if (HIWORD(wParam) == CBN_SELCHANGE ||
516 {
517 pPortData->bChanged = TRUE;
518 }
519 break;
520
521// case IDC_SERIAL_ADVANCED:
522
524 RestoreDefaultValues(hwnd, pPortData);
525 break;
526
527 default:
528 break;
529 }
530}
#define ERR(fmt,...)
Definition: debug.h:110
WPARAM wParam
Definition: combotst.c:138
#define TRUE
Definition: types.h:120
#define IDC_SERIAL_BITSPERSECOND
Definition: resource.h:4
#define IDC_SERIAL_DATABITS
Definition: resource.h:5
#define IDC_SERIAL_RESTORE
Definition: resource.h:10
#define IDC_SERIAL_STOPBITS
Definition: resource.h:7
#define IDC_SERIAL_PARITY
Definition: resource.h:6
#define IDC_SERIAL_FLOWCONTROL
Definition: resource.h:8
static VOID RestoreDefaultValues(HWND hwnd, PPORT_DATA pPortData)
Definition: serial.c:444
struct _PORT_DATA * PPORT_DATA
#define LOWORD(l)
Definition: pedump.c:82
#define TRACE(s)
Definition: solgame.cpp:4
BOOL bChanged
Definition: serial.c:24
#define GetWindowLongPtr
Definition: treelist.c:73
#define HIWORD(l)
Definition: typedefs.h:247
#define DWLP_USER
Definition: winuser.h:872
#define CBN_SELCHANGE
Definition: winuser.h:1979
#define CBN_EDITCHANGE
Definition: winuser.h:1975

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
569 if (pPortData == NULL)
570 {
571 ERR("pPortData is NULL\n");
572 return;
573 }
574
575 HeapFree(GetProcessHeap(), 0, pPortData);
577}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define SetWindowLongPtr
Definition: treelist.c:70

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
374
375 /* Read and parse the port settings */
376 ReadPortSettings(pPortData);
377
378 /* Fill the 'Bits per second' combobox */
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}
HINSTANCE hInstance
Definition: charmap.c:19
LPARAM lParam
Definition: combotst.c:139
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define IDC_SERIAL_ADVANCED
Definition: resource.h:9
#define IDS_FLOWCONTROL
Definition: resource.h:22
#define IDS_STOPBITS
Definition: resource.h:21
#define IDS_PARITY
Definition: resource.h:20
static VOID FillComboBox(HWND hwnd, PWSTR szBuffer)
Definition: serial.c:43
DWORD BaudRates[]
Definition: serial.c:33
PWSTR DataBits[]
Definition: serial.c:36
static VOID ReadPortSettings(PPORT_DATA pPortData)
Definition: serial.c:68
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
_CRTIMP wchar_t *__cdecl _ultow(_In_ unsigned long _Value, _Pre_notnull_ _Post_z_ wchar_t *_Dest, _In_ int _Radix)
unsigned int UINT
Definition: ndis.h:50
INT nFlowControlIndex
Definition: serial.c:22
INT nParityIndex
Definition: serial.c:19
INT nDataBitsIndex
Definition: serial.c:20
INT nStopBitsIndex
Definition: serial.c:21
INT nBaudRateIndex
Definition: serial.c:18
#define ComboBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:66
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
__wchar_t WCHAR
Definition: xmlstorage.h:180

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
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}
#define FIXME(fmt,...)
Definition: debug.h:111
static VOID WritePortSettings(HWND hwnd, PPORT_DATA pPortData)
Definition: serial.c:228
#define PSN_APPLY
Definition: prsht.h:117
Definition: inflate.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
92 pPortData->DeviceInfoData,
94 0,
96 KEY_READ);
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);
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);
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 RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define DEFAULT_STOP_BITS_INDEX
Definition: serial.c:30
#define DEFAULT_PARITY_INDEX
Definition: serial.c:29
PWSTR StopBits[]
Definition: serial.c:37
PWSTR Paritys[]
Definition: serial.c:35
PWSTR FlowControls[]
Definition: serial.c:38
#define DEFAULT_FLOW_CONTROL_INDEX
Definition: serial.c:31
#define DEFAULT_DATA_BITS_INDEX
Definition: serial.c:28
#define DEFAULT_BAUD_RATE_INDEX
Definition: serial.c:27
HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired)
Definition: devinst.c:5934
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLdouble n
Definition: glext.h:7729
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_READ
Definition: nt_native.h:1023
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define DIREG_DEV
Definition: setupapi.h:181
#define DICS_FLAG_GLOBAL
Definition: setupapi.h:113
WCHAR szPortName[16]
Definition: parallel.c:17
PSP_DEVINFO_DATA DeviceInfoData
Definition: parallel.c:15
HDEVINFO DeviceInfoSet
Definition: parallel.c:14
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

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 */
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}

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}
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
Definition: propsheet.c:3083
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
Definition: propsheet.c:3152
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define IDD_SERIALSETTINGS
Definition: resource.h:3
static INT_PTR CALLBACK SerialSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: serial.c:583
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
struct _PROPSHEETPAGEW PROPSHEETPAGEW
#define SPPSR_ENUM_ADV_DEVICE_PROPERTIES
Definition: setupapi.h:615
PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1104
LONG_PTR LPARAM
Definition: windef.h:208
#define MAKEINTRESOURCE
Definition: winuser.h:591

◆ 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:
605 break;
606 }
607
608 return FALSE;
609}
static VOID OnDestroy(HWND hwnd)
Definition: serial.c:561
static VOID OnNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: serial.c:535
static VOID OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: serial.c:491
static BOOL OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: serial.c:354
#define WM_NOTIFY
Definition: richedit.h:61
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
#define WM_DESTROY
Definition: winuser.h:1609

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
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
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}
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:4882
BOOL WINAPI SetupDiCallClassInstaller(DI_FUNCTION InstallFunction, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:4024
#define swprintf
Definition: precomp.h:40
#define KEY_WRITE
Definition: nt_native.h:1031
struct _SP_CLASSINSTALL_HEADER SP_CLASSINSTALL_HEADER
#define SetupDiSetClassInstallParams
Definition: setupapi.h:2617
#define DICS_PROPCHANGE
Definition: setupapi.h:116
#define DIF_PROPERTYCHANGE
Definition: setupapi.h:137
DI_FUNCTION InstallFunction
Definition: setupapi.h:904
SP_CLASSINSTALL_HEADER ClassInstallHeader
Definition: setupapi.h:916
#define ComboBox_GetCurSel(hwndCtl)
Definition: windowsx.h:49
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define HWND_BROADCAST
Definition: winuser.h:1204
#define WM_WININICHANGE
Definition: winuser.h:1630

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"}

◆ 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"}