|
2 | 2 | * SerialPort_Windows.c
|
3 | 3 | *
|
4 | 4 | * Created on: Feb 25, 2012
|
5 |
| - * Last Updated on: Apr 22, 2024 |
| 5 | + * Last Updated on: May 15, 2024 |
6 | 6 | * Author: Will Hedgecock
|
7 | 7 | *
|
8 | 8 | * Copyright (C) 2012-2024 Fazecast, Inc.
|
@@ -268,12 +268,13 @@ static void enumeratePorts(JNIEnv *env)
|
268 | 268 | }
|
269 | 269 |
|
270 | 270 | // Fetch the physical location for this device
|
| 271 | + DWORD locationLength = 0; |
271 | 272 | wchar_t *locationString = NULL;
|
272 |
| - DWORD locationLength = 0, busNumber = -1, hubNumber = -1, portNumber = -1; |
| 273 | + unsigned long busNumber = 0, hubNumber = 0, portNumber = 0; |
273 | 274 | if (!SetupDiGetDeviceRegistryPropertyW(devList, &devInfoData, SPDRP_BUSNUMBER, NULL, (BYTE*)&busNumber, sizeof(busNumber), NULL))
|
274 |
| - busNumber = -1; |
| 275 | + busNumber = 0; |
275 | 276 | if (!SetupDiGetDeviceRegistryPropertyW(devList, &devInfoData, SPDRP_ADDRESS, NULL, (BYTE*)&portNumber, sizeof(portNumber), NULL))
|
276 |
| - portNumber = -1; |
| 277 | + portNumber = 0; |
277 | 278 | SetupDiGetDeviceRegistryPropertyW(devList, &devInfoData, SPDRP_LOCATION_INFORMATION, NULL, NULL, 0, &locationLength);
|
278 | 279 | if (locationLength && (locationLength < 256))
|
279 | 280 | {
|
@@ -336,15 +337,9 @@ static void enumeratePorts(JNIEnv *env)
|
336 | 337 | if (locationString)
|
337 | 338 | free(locationString);
|
338 | 339 | }
|
339 |
| - if (busNumber == -1) |
340 |
| - busNumber = 0; |
341 |
| - if (hubNumber == -1) |
342 |
| - hubNumber = 0; |
343 |
| - if (portNumber == -1) |
344 |
| - portNumber = 0; |
345 |
| - locationString = (wchar_t*)malloc(16*sizeof(wchar_t)); |
| 340 | + locationString = (wchar_t*)malloc(32*sizeof(wchar_t)); |
346 | 341 | if (locationString)
|
347 |
| - _snwprintf_s(locationString, 16, 16, L"%d-%d.%d", busNumber, hubNumber, portNumber); |
| 342 | + _snwprintf_s(locationString, 32, _TRUNCATE, L"%lu-%lu.%lu", busNumber, hubNumber, portNumber); |
348 | 343 | else
|
349 | 344 | {
|
350 | 345 | free(comPort);
|
|
0 commit comments