Commit efe40a72c503808d1460b16794c4f06dabb691e0

Authored by Perry Werneck
1 parent 1373009b
Exists in master and in 1 other branch develop

Implementing MSVC version.

@@ -25,4 +25,9 @@ doxygen/html @@ -25,4 +25,9 @@ doxygen/html
25 doxygen/rtf 25 doxygen/rtf
26 *~ 26 *~
27 *.pc 27 *.pc
  28 +*.obj
  29 +*.dll
  30 +*.exe
  31 +*.exp
  32 +*.lib
28 33
@@ -82,3 +82,26 @@ TODO @@ -82,3 +82,26 @@ TODO
82 $ make install 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 + ```
clean.bat 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +@echo off
  2 +nmake /f win\Makefile.msc clean
src/core/windows/init.cc
@@ -36,13 +36,18 @@ @@ -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 #include <winsock2.h> 39 #include <winsock2.h>
45 #include <windows.h> 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 #include "../private.h" 51 #include "../private.h"
47 #include <lmcons.h> 52 #include <lmcons.h>
48 #include <delayimp.h> 53 #include <delayimp.h>
@@ -50,33 +55,52 @@ @@ -50,33 +55,52 @@
50 #include <string> 55 #include <string>
51 #include <stdexcept> 56 #include <stdexcept>
52 #include <lib3270.h> 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 extern "C" { 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 extern __declspec (dllexport) HRESULT DllRegisterServer(); 80 extern __declspec (dllexport) HRESULT DllRegisterServer();
66 extern __declspec (dllexport) HRESULT DllInstall(BOOL, PCWSTR); 81 extern __declspec (dllexport) HRESULT DllInstall(BOOL, PCWSTR);
  82 + extern __declspec (dllexport) HRESULT DllUnregisterServer();
  83 +
  84 + #endif // MSC_VER
67 85
68 FARPROC WINAPI hllapi_delay_load_hook(unsigned reason, DelayLoadInfo * info); 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 static HANDLE hModule = 0; 105 static HANDLE hModule = 0;
82 static HANDLE hEventLog = 0; 106 static HANDLE hEventLog = 0;
@@ -85,6 +109,10 @@ @@ -85,6 +109,10 @@
85 return S_OK; 109 return S_OK;
86 } 110 }
87 111
  112 + HRESULT DllUnregisterServer() {
  113 + return S_OK;
  114 + }
  115 +
88 HRESULT DllInstall(BOOL bInstall, PCWSTR pszCmdLine) { 116 HRESULT DllInstall(BOOL bInstall, PCWSTR pszCmdLine) {
89 return S_OK; 117 return S_OK;
90 } 118 }
@@ -108,39 +136,44 @@ @@ -108,39 +136,44 @@
108 return TRUE; 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 static void dummyProc() { 177 static void dummyProc() {
145 throw std::runtime_error(_("Operation not supported")); 178 throw std::runtime_error(_("Operation not supported"));
146 } 179 }
@@ -149,6 +182,8 @@ @@ -149,6 +182,8 @@
149 182
150 static string savedpath; 183 static string savedpath;
151 184
  185 + printf("%s\n",__FUNCTION__);
  186 +
152 // https://docs.microsoft.com/en-us/cpp/build/reference/structure-and-constant-definitions?view=vs-2019 187 // https://docs.microsoft.com/en-us/cpp/build/reference/structure-and-constant-definitions?view=vs-2019
153 switch (reason) { 188 switch (reason) {
154 case dliNoteStartProcessing: 189 case dliNoteStartProcessing:
@@ -197,15 +232,16 @@ @@ -197,15 +232,16 @@
197 { 232 {
198 string msg = "Can't load "; 233 string msg = "Can't load ";
199 msg += (const char *) info->szDll; 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 case dliFailGetProc: 239 case dliFailGetProc:
205 { 240 {
  241 + // TODO: Check usage of RaiseException ?
206 string msg = "Can't find method on "; 242 string msg = "Can't find method on ";
207 msg += (const char *) info->szDll; 243 msg += (const char *) info->szDll;
208 - eventlog(msg.c_str()); 244 + hllapi_report_event((LPSTR) msg.c_str());
209 } 245 }
210 return (FARPROC) dummyProc; 246 return (FARPROC) dummyProc;
211 247
@@ -217,5 +253,4 @@ @@ -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,6 +360,12 @@
360 HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col); 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 * @brief Get cursor address. 369 * @brief Get cursor address.
364 * 370 *
365 * @return Cursor address. 371 * @return Cursor address.
src/testprogram/testprogram.cc
@@ -50,6 +50,8 @@ @@ -50,6 +50,8 @@
50 50
51 int main(int argc, char **argv) { 51 int main(int argc, char **argv) {
52 52
  53 + printf("******\n");
  54 +
53 char buffer[SCREEN_LENGTH+1]; 55 char buffer[SCREEN_LENGTH+1];
54 56
55 const char *host = ""; 57 const char *host = "";
@@ -269,7 +271,13 @@ @@ -269,7 +271,13 @@
269 cout.flush(); 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 rc = hllapi_wait_for_ready(10); 283 rc = hllapi_wait_for_ready(10);
@@ -314,9 +322,4 @@ @@ -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,6 +47,7 @@ OBJ_FILES= \
47 /DPRODUCT_NAME=$(PRODUCT_NAME) \ 47 /DPRODUCT_NAME=$(PRODUCT_NAME) \
48 /DLIB3270_NAME=$(LIB3270_NAME) \ 48 /DLIB3270_NAME=$(LIB3270_NAME) \
49 /DNDEBUG=1 \ 49 /DNDEBUG=1 \
  50 + /DUSING_STATIC_IPC3270 \
50 /I".\src\include" \ 51 /I".\src\include" \
51 /I"$(PW3270_SDK_PATH)\include" \ 52 /I"$(PW3270_SDK_PATH)\include" \
52 /EHsc \ 53 /EHsc \
@@ -60,6 +61,7 @@ testprogram.exe: \ @@ -60,6 +61,7 @@ testprogram.exe: \
60 @link \ 61 @link \
61 /nologo \ 62 /nologo \
62 /OUT:"$@" \ 63 /OUT:"$@" \
  64 + /LIBPATH:. \
63 /LIBPATH:"$(PW3270_SDK_PATH)\lib" \ 65 /LIBPATH:"$(PW3270_SDK_PATH)\lib" \
64 src\testprogram\testprogram.obj 66 src\testprogram\testprogram.obj
65 67
@@ -72,11 +74,11 @@ hllapi.dll: \ @@ -72,11 +74,11 @@ hllapi.dll: \
72 /OUT:"$@" \ 74 /OUT:"$@" \
73 /LIBPATH:"$(PW3270_SDK_PATH)\lib" \ 75 /LIBPATH:"$(PW3270_SDK_PATH)\lib" \
74 $(OBJ_FILES) \ 76 $(OBJ_FILES) \
75 - "ipc3270.lib \  
76 - Advapi32.lib 77 + /DELAYLOAD:$(LIB3270_NAME).dll
  78 +
77 79
78 install: \ 80 install: \
79 - $(OBJ_FILES) 81 + hllapi.dll
80 @echo Building library... 82 @echo Building library...
81 @-mkdir "$(PW3270_SDK_PATH)\lib" 83 @-mkdir "$(PW3270_SDK_PATH)\lib"
82 @lib \ 84 @lib \
@@ -86,6 +88,7 @@ install: \ @@ -86,6 +88,7 @@ install: \
86 88
87 @-mkdir "$(PW3270_SDK_PATH)\include\lib3270" 89 @-mkdir "$(PW3270_SDK_PATH)\include\lib3270"
88 @copy "src\include\lib3270\*.h" "$(PW3270_SDK_PATH)\include\lib3270" 90 @copy "src\include\lib3270\*.h" "$(PW3270_SDK_PATH)\include\lib3270"
  91 + @copy hllapi.dll "$(SystemRoot)\system32"
89 92
90 clean: 93 clean:
91 del \ 94 del \