diff --git a/lib3270.cbp b/lib3270.cbp index 0d5f86e..4c91b75 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -212,9 +212,6 @@ - - @@ -233,7 +230,9 @@ - + + diff --git a/src/core/init.c b/src/core/init.c index d73fcb3..4093934 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -160,23 +160,30 @@ int lib3270_unloaded(void) BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwcallpurpose, LPVOID GNUC_UNUSED(lpvResvd)) { + debug("%s starts",__FUNCTION__); + switch(dwcallpurpose) { case DLL_PROCESS_ATTACH: hModule = hInstance; - hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME)); + hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME)); get_version_info(); lib3270_loaded(); break; case DLL_PROCESS_DETACH: lib3270_unloaded(); - DeregisterEventSource(hEventLog); - hEventLog = 0; + if(hEventLog) + { + DeregisterEventSource(hEventLog); + } + hEventLog = NULL; break; } + debug("%s ends",__FUNCTION__); + return TRUE; } diff --git a/src/core/windows/connect.c b/src/core/windows/connect.c index 7c018a5..888dc88 100644 --- a/src/core/windows/connect.c +++ b/src/core/windows/connect.c @@ -238,6 +238,7 @@ int net_reconnect(H3270 *hSession, int seconds) debug("host.message=\"%s\"",host.message); + if(hEventLog) { // Register on event log lib3270_autoptr(char) username = lib3270_get_user_name(); diff --git a/src/core/windows/log.c b/src/core/windows/log.c index 603b708..e1f1e05 100644 --- a/src/core/windows/log.c +++ b/src/core/windows/log.c @@ -43,31 +43,38 @@ void default_log_writer(H3270 GNUC_UNUSED(*session), const char *module, int rc, const char *fmt, va_list arg_ptr) { - lib3270_autoptr(char) username = lib3270_get_user_name(); lib3270_autoptr(char) msg = lib3270_vsprintf(fmt,arg_ptr); - const char *outMsg[] = { - username, - module, - msg - }; + debug("%s",msg); -#ifdef DEBUG - fprintf(stderr,"LOG(%s): %s\n",module,msg); - fflush(stderr); -#endif // DEBUG + if(hEventLog) + { + lib3270_autoptr(char) username = lib3270_get_user_name(); - ReportEvent( - hEventLog, - (rc == 0 ? EVENTLOG_INFORMATION_TYPE : EVENTLOG_ERROR_TYPE), - 1, - 0, - NULL, - 3, - 0, - outMsg, - NULL - ); + const char *outMsg[] = { + username, + module, + msg + }; + + #ifdef DEBUG + fprintf(stderr,"LOG(%s): %s\n",module,msg); + fflush(stderr); + #endif // DEBUG + + ReportEvent( + hEventLog, + (rc == 0 ? EVENTLOG_INFORMATION_TYPE : EVENTLOG_ERROR_TYPE), + 1, + 0, + NULL, + 3, + 0, + outMsg, + NULL + ); + + } } diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index abb9d2b..1c5b62a 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -36,9 +36,9 @@ static void online_group_state_changed(H3270 GNUC_UNUSED(*hSession), void GNUC_U int main(int argc, char *argv[]) { -#ifdef _WIN32 +#ifdef DEBUG printf("Process %s running on pid %u\n",argv[0],(unsigned int) GetCurrentProcessId()); -#endif // _WIN32 +#endif // DEBUG #ifdef LC_ALL setlocale( LC_ALL, "" ); @@ -61,6 +61,8 @@ int main(int argc, char *argv[]) H3270 * h = lib3270_session_new(""); int rc = 0; + lib3270_write_log(h,"TEST","Testprogram %s starts (%s)",argv[0],LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME)); + lib3270_autoptr(char) version_info = lib3270_get_version_info(); printf("3270 session %p created\n%s\n]",h,version_info); -- libgit2 0.21.2