Commit efe40a72c503808d1460b16794c4f06dabb691e0
1 parent
1373009b
Exists in
master
and in
1 other branch
Implementing MSVC version.
Showing
7 changed files
with
134 additions
and
57 deletions
Show diff stats
.gitignore
README.md
| ... | ... | @@ -82,3 +82,26 @@ TODO |
| 82 | 82 | $ make install |
| 83 | 83 | ``` |
| 84 | 84 | |
| 85 | +### Windows native with MSVC | |
| 86 | + | |
| 87 | +1. Install pw3270 with remote control and sdk modules | |
| 88 | + | |
| 89 | +2. Download and install Visual Studio Build Tools (https://visualstudio.microsoft.com/pt-br/downloads/) | |
| 90 | + | |
| 91 | +3. Download and install git for windows | |
| 92 | + | |
| 93 | +4. Build and install the "glue" library using the MSVC Native tools command prompt as administrator. | |
| 94 | + | |
| 95 | + ```shell | |
| 96 | + git clone https://github.com/PerryWerneck/libipc3270.git ./ipc3270 | |
| 97 | + cd ipc3270 | |
| 98 | + install.bat | |
| 99 | + ``` | |
| 100 | + | |
| 101 | +5. Build and install hllapi library using the MSVC Native tools command prompt as administrator. | |
| 102 | + | |
| 103 | + ```shell | |
| 104 | + git clone https://github.com/PerryWerneck/libhllapi.git ./hllapi | |
| 105 | + cd hllapi | |
| 106 | + install.bat | |
| 107 | + ``` | ... | ... |
src/core/windows/init.cc
| ... | ... | @@ -36,13 +36,18 @@ |
| 36 | 36 | * |
| 37 | 37 | */ |
| 38 | 38 | |
| 39 | -#ifndef _MSC_VER | |
| 40 | - #include <config.h> | |
| 41 | - #pragma comment(lib,"Advapi32.lib") | |
| 42 | -#endif // !_MSC_VER | |
| 43 | - | |
| 44 | 39 | #include <winsock2.h> |
| 45 | 40 | #include <windows.h> |
| 41 | + | |
| 42 | + #ifdef _MSC_VER | |
| 43 | + #pragma comment(lib,"Advapi32.lib") | |
| 44 | + #pragma comment(lib,"ipc3270.lib") | |
| 45 | + #pragma comment(lib,"Delayimp.lib") | |
| 46 | + #include <Delayimp.h> | |
| 47 | + #else | |
| 48 | + #include <config.h> | |
| 49 | + #endif // !_MSC_VER | |
| 50 | + | |
| 46 | 51 | #include "../private.h" |
| 47 | 52 | #include <lmcons.h> |
| 48 | 53 | #include <delayimp.h> |
| ... | ... | @@ -50,33 +55,52 @@ |
| 50 | 55 | #include <string> |
| 51 | 56 | #include <stdexcept> |
| 52 | 57 | #include <lib3270.h> |
| 58 | + #include <lib3270/hllapi.h> | |
| 59 | + | |
| 60 | + #ifdef HAVE_LIBINTL | |
| 61 | + #include <libintl.h> | |
| 62 | + #endif // HAVE_LIBINTL | |
| 53 | 63 | |
| 54 | -#ifdef HAVE_LIBINTL | |
| 55 | - #include <libintl.h> | |
| 56 | -#endif // HAVE_LIBINTL | |
| 57 | - | |
| 58 | - #ifdef USING_STATIC_IPC3270 | |
| 64 | + using namespace std; | |
| 59 | 65 | |
| 60 | 66 | extern "C" { |
| 61 | 67 | |
| 62 | - extern __declspec (dllexport) PfnDliHook __pfnDliNotifyHook2; | |
| 63 | - extern __declspec (dllexport) PfnDliHook __pfnDliFailureHook2; | |
| 68 | + #ifdef _MSC_VER | |
| 69 | + | |
| 70 | + #pragma comment(linker, "/EXPORT:DllRegisterServer=DllRegisterServer,PRIVATE") | |
| 71 | + #pragma comment(linker, "/EXPORT:DllUnregisterServer=DllUnregisterServer,PRIVATE") | |
| 72 | + #pragma comment(linker, "/EXPORT:DllInstall=DllInstall,PRIVATE") | |
| 73 | + | |
| 74 | + extern HRESULT DllRegisterServer(); | |
| 75 | + extern HRESULT DllInstall(BOOL, PCWSTR); | |
| 76 | + extern HRESULT DllUnregisterServer(); | |
| 77 | + | |
| 78 | + #else | |
| 64 | 79 | |
| 65 | 80 | extern __declspec (dllexport) HRESULT DllRegisterServer(); |
| 66 | 81 | extern __declspec (dllexport) HRESULT DllInstall(BOOL, PCWSTR); |
| 82 | + extern __declspec (dllexport) HRESULT DllUnregisterServer(); | |
| 83 | + | |
| 84 | + #endif // MSC_VER | |
| 67 | 85 | |
| 68 | 86 | FARPROC WINAPI hllapi_delay_load_hook(unsigned reason, DelayLoadInfo * info); |
| 69 | 87 | |
| 70 | 88 | } |
| 71 | 89 | |
| 72 | - using std::string; | |
| 90 | +#ifdef USING_STATIC_IPC3270 | |
| 73 | 91 | |
| 74 | -/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 92 | + // https://docs.microsoft.com/en-us/cpp/build/reference/loading-all-imports-for-a-delay-loaded-dll?view=vs-2019 | |
| 93 | + #ifdef _MSC_VER | |
| 94 | + const PfnDliHook __pfnDliNotifyHook2 = hllapi_delay_load_hook; | |
| 95 | + const PfnDliHook __pfnDliFailureHook2 = hllapi_delay_load_hook; | |
| 96 | + #else | |
| 97 | + PfnDliHook __pfnDliNotifyHook2 = hllapi_delay_load_hook; | |
| 98 | + PfnDliHook __pfnDliFailureHook2 = hllapi_delay_load_hook; | |
| 99 | + #endif // _MSC_VER | |
| 75 | 100 | |
| 76 | - // https://docs.microsoft.com/en-us/cpp/build/reference/loading-all-imports-for-a-delay-loaded-dll?view=vs-2019 | |
| 101 | +#endif // USING_STATIC_IPC3270 | |
| 77 | 102 | |
| 78 | - PfnDliHook __pfnDliNotifyHook2 = hllapi_delay_load_hook; | |
| 79 | - PfnDliHook __pfnDliFailureHook2 = hllapi_delay_load_hook; | |
| 103 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 80 | 104 | |
| 81 | 105 | static HANDLE hModule = 0; |
| 82 | 106 | static HANDLE hEventLog = 0; |
| ... | ... | @@ -85,6 +109,10 @@ |
| 85 | 109 | return S_OK; |
| 86 | 110 | } |
| 87 | 111 | |
| 112 | + HRESULT DllUnregisterServer() { | |
| 113 | + return S_OK; | |
| 114 | + } | |
| 115 | + | |
| 88 | 116 | HRESULT DllInstall(BOOL bInstall, PCWSTR pszCmdLine) { |
| 89 | 117 | return S_OK; |
| 90 | 118 | } |
| ... | ... | @@ -108,39 +136,44 @@ |
| 108 | 136 | return TRUE; |
| 109 | 137 | } |
| 110 | 138 | |
| 111 | - static void eventlog(const char *msg) { | |
| 139 | + HLLAPI_API_CALL hllapi_report_event(LPSTR message) { | |
| 112 | 140 | |
| 113 | - char username[UNLEN + 1]; | |
| 114 | - DWORD szName = sizeof(username); | |
| 141 | + char username[UNLEN + 1]; | |
| 142 | + DWORD szName = sizeof(username); | |
| 115 | 143 | |
| 116 | - memset(username,0,UNLEN + 1); | |
| 144 | + memset(username,0,UNLEN + 1); | |
| 117 | 145 | |
| 118 | - if(!GetUserName(username, &szName)) { | |
| 119 | - username[0] = 0; | |
| 120 | - } | |
| 146 | + if(!GetUserName(username, &szName)) { | |
| 147 | + username[0] = 0; | |
| 148 | + } | |
| 149 | + | |
| 150 | + const char *outMsg[] = { | |
| 151 | + username, | |
| 152 | + PACKAGE_NAME, | |
| 153 | + message | |
| 154 | + }; | |
| 155 | + | |
| 156 | + debug("Event: \"%s\"",msg); | |
| 121 | 157 | |
| 122 | - const char *outMsg[] = { | |
| 123 | - username, | |
| 124 | - PACKAGE_NAME, | |
| 125 | - msg | |
| 126 | - }; | |
| 127 | - | |
| 128 | - debug("Event: \"%s\"",msg); | |
| 129 | - | |
| 130 | - ReportEvent( | |
| 131 | - hEventLog, | |
| 132 | - EVENTLOG_ERROR_TYPE, | |
| 133 | - 1, | |
| 134 | - 0, | |
| 135 | - NULL, | |
| 136 | - 3, | |
| 137 | - 0, | |
| 138 | - outMsg, | |
| 139 | - NULL | |
| 140 | - ); | |
| 158 | + ReportEvent( | |
| 159 | + hEventLog, | |
| 160 | + EVENTLOG_ERROR_TYPE, | |
| 161 | + 1, | |
| 162 | + 0, | |
| 163 | + NULL, | |
| 164 | + 3, | |
| 165 | + 0, | |
| 166 | + outMsg, | |
| 167 | + NULL | |
| 168 | + ); | |
| 169 | + | |
| 170 | + return HLLAPI_STATUS_SUCCESS; | |
| 141 | 171 | |
| 142 | 172 | } |
| 143 | 173 | |
| 174 | + | |
| 175 | +#ifdef USING_STATIC_IPC3270 | |
| 176 | + | |
| 144 | 177 | static void dummyProc() { |
| 145 | 178 | throw std::runtime_error(_("Operation not supported")); |
| 146 | 179 | } |
| ... | ... | @@ -149,6 +182,8 @@ |
| 149 | 182 | |
| 150 | 183 | static string savedpath; |
| 151 | 184 | |
| 185 | + printf("%s\n",__FUNCTION__); | |
| 186 | + | |
| 152 | 187 | // https://docs.microsoft.com/en-us/cpp/build/reference/structure-and-constant-definitions?view=vs-2019 |
| 153 | 188 | switch (reason) { |
| 154 | 189 | case dliNoteStartProcessing: |
| ... | ... | @@ -197,15 +232,16 @@ |
| 197 | 232 | { |
| 198 | 233 | string msg = "Can't load "; |
| 199 | 234 | msg += (const char *) info->szDll; |
| 200 | - eventlog(msg.c_str()); | |
| 235 | + hllapi_report_event((LPSTR) msg.c_str()); | |
| 201 | 236 | } |
| 202 | - return (FARPROC) hModule; | |
| 237 | + break; | |
| 203 | 238 | |
| 204 | 239 | case dliFailGetProc: |
| 205 | 240 | { |
| 241 | + // TODO: Check usage of RaiseException ? | |
| 206 | 242 | string msg = "Can't find method on "; |
| 207 | 243 | msg += (const char *) info->szDll; |
| 208 | - eventlog(msg.c_str()); | |
| 244 | + hllapi_report_event((LPSTR) msg.c_str()); | |
| 209 | 245 | } |
| 210 | 246 | return (FARPROC) dummyProc; |
| 211 | 247 | |
| ... | ... | @@ -217,5 +253,4 @@ |
| 217 | 253 | |
| 218 | 254 | } |
| 219 | 255 | |
| 220 | - #endif // USING_STATIC_IPC3270 | |
| 221 | - | |
| 256 | +#endif // USING_STATIC_IPC3270 | ... | ... |
src/include/lib3270/hllapi.h
| ... | ... | @@ -360,6 +360,12 @@ |
| 360 | 360 | HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col); |
| 361 | 361 | |
| 362 | 362 | /** |
| 363 | + * @brief Report event to system log | |
| 364 | + * | |
| 365 | + */ | |
| 366 | + HLLAPI_API_CALL hllapi_report_event(LPSTR message); | |
| 367 | + | |
| 368 | + /** | |
| 363 | 369 | * @brief Get cursor address. |
| 364 | 370 | * |
| 365 | 371 | * @return Cursor address. | ... | ... |
src/testprogram/testprogram.cc
| ... | ... | @@ -50,6 +50,8 @@ |
| 50 | 50 | |
| 51 | 51 | int main(int argc, char **argv) { |
| 52 | 52 | |
| 53 | + printf("******\n"); | |
| 54 | + | |
| 53 | 55 | char buffer[SCREEN_LENGTH+1]; |
| 54 | 56 | |
| 55 | 57 | const char *host = ""; |
| ... | ... | @@ -269,7 +271,13 @@ |
| 269 | 271 | cout.flush(); |
| 270 | 272 | } |
| 271 | 273 | |
| 272 | - /* | |
| 274 | + rc = hllapi_deinit(); | |
| 275 | + cout << "hllapi_deinit exits with rc=" << rc << endl; | |
| 276 | + | |
| 277 | + return 0; | |
| 278 | + } | |
| 279 | + | |
| 280 | + /* | |
| 273 | 281 | |
| 274 | 282 | |
| 275 | 283 | rc = hllapi_wait_for_ready(10); |
| ... | ... | @@ -314,9 +322,4 @@ |
| 314 | 322 | |
| 315 | 323 | */ |
| 316 | 324 | |
| 317 | - rc = hllapi_deinit(); | |
| 318 | - cout << "hllapi_deinit exits with rc=" << rc << endl; | |
| 319 | - | |
| 320 | - return 0; | |
| 321 | - } | |
| 322 | 325 | ... | ... |
win/Makefile.msc
| ... | ... | @@ -47,6 +47,7 @@ OBJ_FILES= \ |
| 47 | 47 | /DPRODUCT_NAME=$(PRODUCT_NAME) \ |
| 48 | 48 | /DLIB3270_NAME=$(LIB3270_NAME) \ |
| 49 | 49 | /DNDEBUG=1 \ |
| 50 | + /DUSING_STATIC_IPC3270 \ | |
| 50 | 51 | /I".\src\include" \ |
| 51 | 52 | /I"$(PW3270_SDK_PATH)\include" \ |
| 52 | 53 | /EHsc \ |
| ... | ... | @@ -60,6 +61,7 @@ testprogram.exe: \ |
| 60 | 61 | @link \ |
| 61 | 62 | /nologo \ |
| 62 | 63 | /OUT:"$@" \ |
| 64 | + /LIBPATH:. \ | |
| 63 | 65 | /LIBPATH:"$(PW3270_SDK_PATH)\lib" \ |
| 64 | 66 | src\testprogram\testprogram.obj |
| 65 | 67 | |
| ... | ... | @@ -72,11 +74,11 @@ hllapi.dll: \ |
| 72 | 74 | /OUT:"$@" \ |
| 73 | 75 | /LIBPATH:"$(PW3270_SDK_PATH)\lib" \ |
| 74 | 76 | $(OBJ_FILES) \ |
| 75 | - "ipc3270.lib \ | |
| 76 | - Advapi32.lib | |
| 77 | + /DELAYLOAD:$(LIB3270_NAME).dll | |
| 78 | + | |
| 77 | 79 | |
| 78 | 80 | install: \ |
| 79 | - $(OBJ_FILES) | |
| 81 | + hllapi.dll | |
| 80 | 82 | @echo Building library... |
| 81 | 83 | @-mkdir "$(PW3270_SDK_PATH)\lib" |
| 82 | 84 | @lib \ |
| ... | ... | @@ -86,6 +88,7 @@ install: \ |
| 86 | 88 | |
| 87 | 89 | @-mkdir "$(PW3270_SDK_PATH)\include\lib3270" |
| 88 | 90 | @copy "src\include\lib3270\*.h" "$(PW3270_SDK_PATH)\include\lib3270" |
| 91 | + @copy hllapi.dll "$(SystemRoot)\system32" | |
| 89 | 92 | |
| 90 | 93 | clean: |
| 91 | 94 | del \ | ... | ... |