From efe40a72c503808d1460b16794c4f06dabb691e0 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 26 Aug 2020 11:57:17 -0300 Subject: [PATCH] Implementing MSVC version. --- .gitignore | 5 +++++ README.md | 23 +++++++++++++++++++++++ clean.bat | 2 ++ src/core/windows/init.cc | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------ src/include/lib3270/hllapi.h | 6 ++++++ src/testprogram/testprogram.cc | 15 +++++++++------ win/Makefile.msc | 9 ++++++--- 7 files changed, 134 insertions(+), 57 deletions(-) create mode 100644 clean.bat diff --git a/.gitignore b/.gitignore index 9642d1a..8678c0d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,9 @@ doxygen/html doxygen/rtf *~ *.pc +*.obj +*.dll +*.exe +*.exp +*.lib diff --git a/README.md b/README.md index bcb8678..d41d4e5 100644 --- a/README.md +++ b/README.md @@ -82,3 +82,26 @@ TODO $ make install ``` +### Windows native with MSVC + +1. Install pw3270 with remote control and sdk modules + +2. Download and install Visual Studio Build Tools (https://visualstudio.microsoft.com/pt-br/downloads/) + +3. Download and install git for windows + +4. Build and install the "glue" library using the MSVC Native tools command prompt as administrator. + + ```shell + git clone https://github.com/PerryWerneck/libipc3270.git ./ipc3270 + cd ipc3270 + install.bat + ``` + +5. Build and install hllapi library using the MSVC Native tools command prompt as administrator. + + ```shell + git clone https://github.com/PerryWerneck/libhllapi.git ./hllapi + cd hllapi + install.bat + ``` diff --git a/clean.bat b/clean.bat new file mode 100644 index 0000000..7faffda --- /dev/null +++ b/clean.bat @@ -0,0 +1,2 @@ +@echo off +nmake /f win\Makefile.msc clean diff --git a/src/core/windows/init.cc b/src/core/windows/init.cc index c77476c..cf2d73f 100644 --- a/src/core/windows/init.cc +++ b/src/core/windows/init.cc @@ -36,13 +36,18 @@ * */ -#ifndef _MSC_VER - #include - #pragma comment(lib,"Advapi32.lib") -#endif // !_MSC_VER - #include #include + + #ifdef _MSC_VER + #pragma comment(lib,"Advapi32.lib") + #pragma comment(lib,"ipc3270.lib") + #pragma comment(lib,"Delayimp.lib") + #include + #else + #include + #endif // !_MSC_VER + #include "../private.h" #include #include @@ -50,33 +55,52 @@ #include #include #include + #include + + #ifdef HAVE_LIBINTL + #include + #endif // HAVE_LIBINTL -#ifdef HAVE_LIBINTL - #include -#endif // HAVE_LIBINTL - - #ifdef USING_STATIC_IPC3270 + using namespace std; extern "C" { - extern __declspec (dllexport) PfnDliHook __pfnDliNotifyHook2; - extern __declspec (dllexport) PfnDliHook __pfnDliFailureHook2; + #ifdef _MSC_VER + + #pragma comment(linker, "/EXPORT:DllRegisterServer=DllRegisterServer,PRIVATE") + #pragma comment(linker, "/EXPORT:DllUnregisterServer=DllUnregisterServer,PRIVATE") + #pragma comment(linker, "/EXPORT:DllInstall=DllInstall,PRIVATE") + + extern HRESULT DllRegisterServer(); + extern HRESULT DllInstall(BOOL, PCWSTR); + extern HRESULT DllUnregisterServer(); + + #else extern __declspec (dllexport) HRESULT DllRegisterServer(); extern __declspec (dllexport) HRESULT DllInstall(BOOL, PCWSTR); + extern __declspec (dllexport) HRESULT DllUnregisterServer(); + + #endif // MSC_VER FARPROC WINAPI hllapi_delay_load_hook(unsigned reason, DelayLoadInfo * info); } - using std::string; +#ifdef USING_STATIC_IPC3270 -/*---[ Implement ]----------------------------------------------------------------------------------*/ + // https://docs.microsoft.com/en-us/cpp/build/reference/loading-all-imports-for-a-delay-loaded-dll?view=vs-2019 + #ifdef _MSC_VER + const PfnDliHook __pfnDliNotifyHook2 = hllapi_delay_load_hook; + const PfnDliHook __pfnDliFailureHook2 = hllapi_delay_load_hook; + #else + PfnDliHook __pfnDliNotifyHook2 = hllapi_delay_load_hook; + PfnDliHook __pfnDliFailureHook2 = hllapi_delay_load_hook; + #endif // _MSC_VER - // https://docs.microsoft.com/en-us/cpp/build/reference/loading-all-imports-for-a-delay-loaded-dll?view=vs-2019 +#endif // USING_STATIC_IPC3270 - PfnDliHook __pfnDliNotifyHook2 = hllapi_delay_load_hook; - PfnDliHook __pfnDliFailureHook2 = hllapi_delay_load_hook; +/*---[ Implement ]----------------------------------------------------------------------------------*/ static HANDLE hModule = 0; static HANDLE hEventLog = 0; @@ -85,6 +109,10 @@ return S_OK; } + HRESULT DllUnregisterServer() { + return S_OK; + } + HRESULT DllInstall(BOOL bInstall, PCWSTR pszCmdLine) { return S_OK; } @@ -108,39 +136,44 @@ return TRUE; } - static void eventlog(const char *msg) { + HLLAPI_API_CALL hllapi_report_event(LPSTR message) { - char username[UNLEN + 1]; - DWORD szName = sizeof(username); + char username[UNLEN + 1]; + DWORD szName = sizeof(username); - memset(username,0,UNLEN + 1); + memset(username,0,UNLEN + 1); - if(!GetUserName(username, &szName)) { - username[0] = 0; - } + if(!GetUserName(username, &szName)) { + username[0] = 0; + } + + const char *outMsg[] = { + username, + PACKAGE_NAME, + message + }; + + debug("Event: \"%s\"",msg); - const char *outMsg[] = { - username, - PACKAGE_NAME, - msg - }; - - debug("Event: \"%s\"",msg); - - ReportEvent( - hEventLog, - EVENTLOG_ERROR_TYPE, - 1, - 0, - NULL, - 3, - 0, - outMsg, - NULL - ); + ReportEvent( + hEventLog, + EVENTLOG_ERROR_TYPE, + 1, + 0, + NULL, + 3, + 0, + outMsg, + NULL + ); + + return HLLAPI_STATUS_SUCCESS; } + +#ifdef USING_STATIC_IPC3270 + static void dummyProc() { throw std::runtime_error(_("Operation not supported")); } @@ -149,6 +182,8 @@ static string savedpath; + printf("%s\n",__FUNCTION__); + // https://docs.microsoft.com/en-us/cpp/build/reference/structure-and-constant-definitions?view=vs-2019 switch (reason) { case dliNoteStartProcessing: @@ -197,15 +232,16 @@ { string msg = "Can't load "; msg += (const char *) info->szDll; - eventlog(msg.c_str()); + hllapi_report_event((LPSTR) msg.c_str()); } - return (FARPROC) hModule; + break; case dliFailGetProc: { + // TODO: Check usage of RaiseException ? string msg = "Can't find method on "; msg += (const char *) info->szDll; - eventlog(msg.c_str()); + hllapi_report_event((LPSTR) msg.c_str()); } return (FARPROC) dummyProc; @@ -217,5 +253,4 @@ } - #endif // USING_STATIC_IPC3270 - +#endif // USING_STATIC_IPC3270 diff --git a/src/include/lib3270/hllapi.h b/src/include/lib3270/hllapi.h index 1563a87..782292d 100644 --- a/src/include/lib3270/hllapi.h +++ b/src/include/lib3270/hllapi.h @@ -360,6 +360,12 @@ HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col); /** + * @brief Report event to system log + * + */ + HLLAPI_API_CALL hllapi_report_event(LPSTR message); + + /** * @brief Get cursor address. * * @return Cursor address. diff --git a/src/testprogram/testprogram.cc b/src/testprogram/testprogram.cc index 7f494d2..fe1ac3e 100644 --- a/src/testprogram/testprogram.cc +++ b/src/testprogram/testprogram.cc @@ -50,6 +50,8 @@ int main(int argc, char **argv) { + printf("******\n"); + char buffer[SCREEN_LENGTH+1]; const char *host = ""; @@ -269,7 +271,13 @@ cout.flush(); } - /* + rc = hllapi_deinit(); + cout << "hllapi_deinit exits with rc=" << rc << endl; + + return 0; + } + + /* rc = hllapi_wait_for_ready(10); @@ -314,9 +322,4 @@ */ - rc = hllapi_deinit(); - cout << "hllapi_deinit exits with rc=" << rc << endl; - - return 0; - } diff --git a/win/Makefile.msc b/win/Makefile.msc index af264c4..7a50aee 100644 --- a/win/Makefile.msc +++ b/win/Makefile.msc @@ -47,6 +47,7 @@ OBJ_FILES= \ /DPRODUCT_NAME=$(PRODUCT_NAME) \ /DLIB3270_NAME=$(LIB3270_NAME) \ /DNDEBUG=1 \ + /DUSING_STATIC_IPC3270 \ /I".\src\include" \ /I"$(PW3270_SDK_PATH)\include" \ /EHsc \ @@ -60,6 +61,7 @@ testprogram.exe: \ @link \ /nologo \ /OUT:"$@" \ + /LIBPATH:. \ /LIBPATH:"$(PW3270_SDK_PATH)\lib" \ src\testprogram\testprogram.obj @@ -72,11 +74,11 @@ hllapi.dll: \ /OUT:"$@" \ /LIBPATH:"$(PW3270_SDK_PATH)\lib" \ $(OBJ_FILES) \ - "ipc3270.lib \ - Advapi32.lib + /DELAYLOAD:$(LIB3270_NAME).dll + install: \ - $(OBJ_FILES) + hllapi.dll @echo Building library... @-mkdir "$(PW3270_SDK_PATH)\lib" @lib \ @@ -86,6 +88,7 @@ install: \ @-mkdir "$(PW3270_SDK_PATH)\include\lib3270" @copy "src\include\lib3270\*.h" "$(PW3270_SDK_PATH)\include\lib3270" + @copy hllapi.dll "$(SystemRoot)\system32" clean: del \ -- libgit2 0.21.2