From 3ad93b329442f36f71ebdd74c69a57a8c6eb1c3b Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 27 Aug 2020 12:32:10 -0300 Subject: [PATCH] Changing 'hllapi_get_last_error' signature to be more compatible with excel macros. --- src/core/controller.cc | 12 +++++++++++- src/include/lib3270/hllapi.h | 5 +++-- src/testprogram/testprogram.cc | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/core/controller.cc b/src/core/controller.cc index 0f70f34..ad3ec2e 100644 --- a/src/core/controller.cc +++ b/src/core/controller.cc @@ -115,7 +115,17 @@ } - HLLAPI_API_CSTR hllapi_get_last_error() { +HLLAPI_API_CALL hllapi_get_last_error(LPSTR lpBuffer, WORD len) { + + strncpy(lpBuffer,hllapi_get_last_error_as_cstring(),len-1); + lpBuffer[len-1] = 0; // Just in case + + return strlen(lpBuffer); +} + + HLLAPI_API_CSTR hllapi_get_last_error_as_cstring() { + return hllapi_lasterror.c_str(); + } diff --git a/src/include/lib3270/hllapi.h b/src/include/lib3270/hllapi.h index 782292d..5b6b82d 100644 --- a/src/include/lib3270/hllapi.h +++ b/src/include/lib3270/hllapi.h @@ -351,7 +351,8 @@ */ HLLAPI_API_CALL hllapi_set_charset(LPSTR charset); - HLLAPI_API_CSTR hllapi_get_last_error(); + HLLAPI_API_CALL hllapi_get_last_error(LPSTR lpBuffer, WORD len); + HLLAPI_API_CSTR hllapi_get_last_error_as_cstring(); HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms); HLLAPI_API_CALL hllapi_set_timeout(WORD seconds); @@ -361,7 +362,7 @@ /** * @brief Report event to system log - * + * */ HLLAPI_API_CALL hllapi_report_event(LPSTR message); diff --git a/src/testprogram/testprogram.cc b/src/testprogram/testprogram.cc index fe1ac3e..38381d6 100644 --- a/src/testprogram/testprogram.cc +++ b/src/testprogram/testprogram.cc @@ -38,9 +38,9 @@ #pragma comment(lib,"hllapi.lib") #define strncasecmp _strnicmp #define strcasecmp _stricmp - #else + #else #include - #endif + #endif #define SCREEN_LENGTH 2000 @@ -91,7 +91,7 @@ int rc = hllapi_init((char *) session); if(rc) { - cout << "hllapi_init returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + cout << "hllapi_init returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; return rc; } @@ -120,7 +120,7 @@ } else if(strcasecmp(cmdline.c_str(),"wait") == 0) { rc = hllapi_wait_for_ready(10); - cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; } else if(strcasecmp(cmdline.c_str(),"disconnect") == 0) { @@ -137,7 +137,7 @@ } else if(strcasecmp(cmdline.c_str(),"contents") == 0) { rc = hllapi_get_screen(0,buffer,SCREEN_LENGTH); - cout << "hllapi_get_screen returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl + cout << "hllapi_get_screen returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl << buffer << endl << endl; } else if(strncasecmp(cmdline.c_str(),"cursor",6) == 0) { @@ -263,7 +263,7 @@ } if(rc != HLLAPI_STATUS_SUCCESS) { - cout << "rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + cout << "rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; rc = HLLAPI_STATUS_SUCCESS; } @@ -282,7 +282,7 @@ rc = hllapi_wait_for_ready(10); if(rc) { - cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; return rc; } @@ -294,7 +294,7 @@ buffer[SCREEN_LENGTH] = 0; rc = hllapi_get_screen(0,buffer,SCREEN_LENGTH); - cout << "hllapi_get_screen returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + cout << "hllapi_get_screen returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; if(rc == HLLAPI_STATUS_SUCCESS) { cout << endl << buffer << endl; @@ -314,11 +314,11 @@ rc = hllapi_disconnect(); if(rc) { - cout << "hllapi_disconnect returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; + cout << "hllapi_disconnect returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; return rc; } - cout << "HLLAPI Last error was \"" << hllapi_get_last_error() << "\"" << endl; + cout << "HLLAPI Last error was \"" << hllapi_get_last_error_as_cstring() << "\"" << endl; */ -- libgit2 0.21.2