|
29 | 29 | #include <jssc_SerialNativeInterface.h> |
30 | 30 | #include "version.h" |
31 | 31 |
|
32 | | -//#include <iostream> |
| 32 | +#if defined(_MSC_VER) && _MSC_VER < 1800 |
| 33 | +# define PRIsz "Iu" |
| 34 | +# define PRIssz "Id" |
| 35 | +#elif defined(__MINGW32__) && !defined(__MINGW64__) |
| 36 | +# define PRIsz "lu" |
| 37 | +# define PRIssz "ld" |
| 38 | +#else |
| 39 | +# define PRIsz "zu" |
| 40 | +# define PRIssz "zd" |
| 41 | +#endif |
33 | 42 |
|
34 | 43 | #define MAX_PORT_NAME_STR_LEN 32 |
35 | 44 |
|
@@ -283,8 +292,8 @@ JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_writeBytes |
283 | 292 | delete overlapped; |
284 | 293 | if( err ){ |
285 | 294 | char emsg[128]; |
286 | | - snprintf(emsg, sizeof emsg, "Error %d: https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes#system-error-codes", err); |
287 | | - jobject *exClz = env->FindClass("jssc/SerialPortException"); |
| 295 | + snprintf(emsg, sizeof emsg, "Error %lu: https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes#system-error-codes", err); |
| 296 | + jclass exClz = env->FindClass("jssc/SerialPortException"); |
288 | 297 | if( exClz ) env->ThrowNew(exClz, emsg); |
289 | 298 | } |
290 | 299 | return returnValue; |
@@ -321,7 +330,7 @@ JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes |
321 | 330 | lpBuffer = (jbyte*)malloc(byteCount*sizeof*lpBuffer); |
322 | 331 | if( !lpBuffer ){ |
323 | 332 | char emsg[32]; emsg[0] = '\0'; |
324 | | - snprintf(emsg, sizeof emsg, "malloc(%d) failed", byteCount*sizeof*lpBuffer); |
| 333 | + snprintf(emsg, sizeof emsg, "malloc(%"PRIsz") failed", byteCount*sizeof*lpBuffer); |
325 | 334 | jclass exClz = env->FindClass("java/lang/RuntimeException"); |
326 | 335 | if( exClz ) env->ThrowNew(exClz, emsg); |
327 | 336 | returnArray = NULL; goto Finally; |
|
0 commit comments