Skip to content

Commit

Permalink
Add Windows flag to optionally allow compiling for older than Vista w…
Browse files Browse the repository at this point in the history
…ith reduced functionality
  • Loading branch information
hedgecrw committed Oct 25, 2022
1 parent 246cd3d commit 6e83bba
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/main/c/Windows/SerialPort_Windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SerialPort_Windows.c
*
* Created on: Feb 25, 2012
* Last Updated on: Oct 24, 2022
* Last Updated on: Oct 25, 2022
* Author: Will Hedgecock
*
* Copyright (C) 2012-2022 Fazecast, Inc.
Expand All @@ -23,10 +23,18 @@
* see <http://www.gnu.org/licenses/> and <http://www.apache.org/licenses/>.
*/

//#define _FORCE_EARLY_WIN_COMPAT

#ifdef _WIN32
#ifdef _FORCE_EARLY_WIN_COMPAT
#define WINVER _WIN32_WINNT_WINXP
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define NTDDI_VERSION NTDDI_WINXP
#else
#define WINVER _WIN32_WINNT_VISTA
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#define NTDDI_VERSION NTDDI_VISTA
#endif
#define WIN32_LEAN_AND_MEAN
#include <initguid.h>
#include <windows.h>
Expand All @@ -42,6 +50,11 @@
#include "ftdi/ftd2xx.h"
#include "WindowsHelperFunctions.h"

#ifdef _FORCE_EARLY_WIN_COMPAT
#define SetupDiGetDevicePropertyW(...) 0
#define CancelIoEx(...) 0
#endif

// Cached class, method, and field IDs
jclass jniErrorClass;
jmethodID serialCommConstructor;
Expand Down Expand Up @@ -138,7 +151,7 @@ static void enumeratePorts(void)
{
comPortLength += sizeof(wchar_t);
comPort = (wchar_t*)malloc(comPortLength);
if (comPort && (RegGetValueW(key, NULL, L"PortName", RRF_RT_REG_SZ, NULL, (LPBYTE)comPort, &comPortLength) == ERROR_SUCCESS))
if (comPort && (RegQueryValueExW(key, L"PortName", NULL, NULL, (LPBYTE)comPort, &comPortLength) == ERROR_SUCCESS))
comPortString = (comPort[0] == L'\\') ? (wcsrchr(comPort, L'\\') + 1) : comPort;
}
RegCloseKey(key);
Expand Down
16 changes: 12 additions & 4 deletions src/main/c/Windows/WindowsHelperFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WindowsHelperFunctions.c
*
* Created on: May 05, 2015
* Last Updated on: Jun 09, 2022
* Last Updated on: Oct 25, 2022
* Author: Will Hedgecock
*
* Copyright (C) 2012-2022 Fazecast, Inc.
Expand All @@ -23,10 +23,18 @@
* see <http://www.gnu.org/licenses/> and <http://www.apache.org/licenses/>.
*/

//#define _FORCE_EARLY_WIN_COMPAT

#ifdef _WIN32
#ifdef _FORCE_EARLY_WIN_COMPAT
#define WINVER _WIN32_WINNT_WINXP
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define NTDDI_VERSION NTDDI_WINXP
#else
#define WINVER _WIN32_WINNT_VISTA
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#define NTDDI_VERSION NTDDI_VISTA
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <direct.h>
Expand Down Expand Up @@ -170,8 +178,8 @@ void reduceLatencyToMinimum(const wchar_t* portName, unsigned char requestElevat
if (RegOpenKeyExW(key, subkey, 0, KEY_QUERY_VALUE, &paramKey) == ERROR_SUCCESS)
{
DWORD oldLatencySize = sizeof(DWORD), portNameSize = maxPortNameSize * sizeof(wchar_t);
if ((RegGetValueW(paramKey, NULL, L"PortName", RRF_RT_REG_SZ, NULL, (LPBYTE)portPath, &portNameSize) == ERROR_SUCCESS) && (wcscmp(portName, portPath) == 0))
RegGetValueW(paramKey, NULL, L"LatencyTimer", RRF_RT_REG_DWORD, NULL, (LPBYTE)&oldLatency, &oldLatencySize);
if ((RegQueryValueExW(paramKey, L"PortName", NULL, NULL, (LPBYTE)portPath, &portNameSize) == ERROR_SUCCESS) && (wcscmp(portName, portPath) == 0))
RegQueryValueExW(paramKey, L"LatencyTimer", NULL, NULL, (LPBYTE)&oldLatency, &oldLatencySize);
RegCloseKey(paramKey);
}
}
Expand Down Expand Up @@ -267,7 +275,7 @@ int getPortPathFromSerial(wchar_t* portPath, int portPathLength, const char* ser
{
DWORD portNameSize = portPathLength;
if ((RegOpenKeyExW(key, subkey, 0, KEY_QUERY_VALUE, &paramKey) == ERROR_SUCCESS) &&
(RegGetValueW(paramKey, NULL, L"PortName", RRF_RT_REG_SZ, NULL, (LPBYTE)portPath, &portNameSize) == ERROR_SUCCESS))
(RegQueryValueExW(paramKey, L"PortName", NULL, NULL, (LPBYTE)portPath, &portNameSize) == ERROR_SUCCESS))
{
found = 1;
RegCloseKey(paramKey);
Expand Down
Binary file modified src/main/resources/Windows/aarch64/jSerialComm.dll
Binary file not shown.
Binary file modified src/main/resources/Windows/armv7/jSerialComm.dll
Binary file not shown.
Binary file modified src/main/resources/Windows/x86/jSerialComm.dll
Binary file not shown.
Binary file modified src/main/resources/Windows/x86_64/jSerialComm.dll
Binary file not shown.

0 comments on commit 6e83bba

Please sign in to comment.