Commit 931588681086ac9b82a86f6442c36cb0c7bd6a29

Authored by perry.werneck@gmail.com
1 parent 8a6093da

Corrigindo problemas encontrados durante teste de uso da libhllapi em LibreOffice for windows

src/include/pw3270/hllapi.h
@@ -75,21 +75,22 @@ extern "C" { @@ -75,21 +75,22 @@ extern "C" {
75 // http://www.mingw.org/wiki/Visual_Basic_DLL 75 // http://www.mingw.org/wiki/Visual_Basic_DLL
76 __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc); 76 __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc);
77 77
78 - __declspec (dllexport) int __stdcall hllapi_init(LPSTR mode);  
79 - __declspec (dllexport) int __stdcall hllapi_deinit(void); 78 + __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode);
  79 + __declspec (dllexport) DWORD __stdcall hllapi_deinit(void);
80 80
81 - __declspec (dllexport) int __stdcall hllapi_get_revision(LPDWORD rc);  
82 - __declspec (dllexport) int __stdcall hllapi_connect(LPSTR uri);  
83 - __declspec (dllexport) int __stdcall hllapi_disconnect(LPWORD rc);  
84 - __declspec (dllexport) int __stdcall hllapi_get_message_id(LPWORD rc);  
85 - __declspec (dllexport) int __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);  
86 - __declspec (dllexport) int __stdcall hllapi_enter(LPWORD rc);  
87 - __declspec (dllexport) int __stdcall hllapi_set_text_at(LPWORD rc, WORD row, WORD col, LPSTR text);  
88 - __declspec (dllexport) int __stdcall hllapi_cmp_text_at(LPWORD rc, WORD row, WORD col, LPSTR text);  
89 - __declspec (dllexport) int __stdcall hllapi_wait_for_ready(LPWORD rc, WORD seconds);  
90 - __declspec (dllexport) int __stdcall hllapi_wait(LPWORD rc, WORD seconds);  
91 - __declspec (dllexport) int __stdcall hllapi_pfkey(LPWORD rc, WORD key);  
92 - __declspec (dllexport) int __stdcall hllapi_pakey(LPWORD rc, WORD key); 81 + __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void);
  82 +
  83 + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri);
  84 + __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
  85 + __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
  86 + __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
  87 + __declspec (dllexport) DWORD __stdcall hllapi_enter(void);
  88 + __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text);
  89 + __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text);
  90 + __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds);
  91 + __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds);
  92 + __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key);
  93 + __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key);
93 94
94 95
95 #else 96 #else
src/lib3270/selection.c
@@ -472,8 +472,11 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) @@ -472,8 +472,11 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len)
472 } 472 }
473 473
474 maxlen = (h->rows * (h->cols+1)) - offset; 474 maxlen = (h->rows * (h->cols+1)) - offset;
475 - if(maxlen <= 0 || offset < 0) 475 + if(maxlen <= 0 || offset < 0)
  476 + {
  477 + errno = EINVAL;
476 return NULL; 478 return NULL;
  479 + }
477 480
478 if(len < 0 || len > maxlen) 481 if(len < 0 || len > maxlen)
479 len = maxlen; 482 len = maxlen;
src/plugins/remotectl/calls.c
@@ -82,10 +82,12 @@ @@ -82,10 +82,12 @@
82 { NULL, NULL } 82 { NULL, NULL }
83 }; 83 };
84 84
  85 +#undef trace
  86 +#define trace(...) { FILE *__dbg = fopen("c:\\users\\perry\\debug.txt","a"); fprintf(__dbg,__VA_ARGS__); fclose(__dbg); }
85 87
86 /*--[ Implement ]------------------------------------------------------------------------------------*/ 88 /*--[ Implement ]------------------------------------------------------------------------------------*/
87 89
88 - __declspec (dllexport) int __stdcall hllapi_init(LPSTR mode) 90 + __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode)
89 { 91 {
90 if(!mode) 92 if(!mode)
91 return EINVAL; 93 return EINVAL;
@@ -98,8 +100,15 @@ @@ -98,8 +100,15 @@
98 // Direct mode, load lib3270.dll, get pointers to the calls 100 // Direct mode, load lib3270.dll, get pointers to the calls
99 int f; 101 int f;
100 102
  103 +#ifdef DEBUG
  104 + // Notify user in case of error loading protocol DLL
  105 + SetErrorMode(0);
  106 +#endif // DEBUG
  107 +
101 hModule = LoadLibrary("lib3270.dll"); 108 hModule = LoadLibrary("lib3270.dll");
102 - if(hModule == NULL) 109 + trace("hModule=%p\n",hModule);
  110 +
  111 + if(!hModule)
103 return GetLastError(); 112 return GetLastError();
104 113
105 // Get library entry pointers 114 // Get library entry pointers
@@ -118,6 +127,8 @@ @@ -118,6 +127,8 @@
118 // Get session handle 127 // Get session handle
119 hSession = session_new(""); 128 hSession = session_new("");
120 129
  130 + trace("%s ok hSession=%p\n",__FUNCTION__,hSession);
  131 +
121 return 0; 132 return 0;
122 } 133 }
123 134
@@ -127,7 +138,7 @@ @@ -127,7 +138,7 @@
127 return -1; 138 return -1;
128 } 139 }
129 140
130 - __declspec (dllexport) int __stdcall hllapi_deinit(void) 141 + __declspec (dllexport) DWORD __stdcall hllapi_deinit(void)
131 { 142 {
132 int f; 143 int f;
133 144
@@ -147,17 +158,14 @@ @@ -147,17 +158,14 @@
147 return 0; 158 return 0;
148 } 159 }
149 160
150 - __declspec (dllexport) int __stdcall hllapi_get_revision(LPDWORD rc) 161 + __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void)
151 { 162 {
152 if(!get_revision) 163 if(!get_revision)
153 - return EINVAL;  
154 -  
155 - *rc = (DWORD) atoi(get_revision());  
156 -  
157 - return 0; 164 + return 0;
  165 + return (DWORD) atoi(get_revision());
158 } 166 }
159 167
160 - __declspec (dllexport) int __stdcall hllapi_connect(LPSTR uri) 168 + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri)
161 { 169 {
162 if(!(host_connect && hSession && uri)) 170 if(!(host_connect && hSession && uri))
163 return EINVAL; 171 return EINVAL;
@@ -165,110 +173,105 @@ @@ -165,110 +173,105 @@
165 return host_connect(hSession,uri,0); 173 return host_connect(hSession,uri,0);
166 } 174 }
167 175
168 - __declspec (dllexport) int __stdcall hllapi_disconnect(LPWORD rc) 176 + __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void)
169 { 177 {
170 if(!(host_disconnect && hSession)) 178 if(!(host_disconnect && hSession))
171 return EINVAL; 179 return EINVAL;
172 180
173 host_disconnect(hSession); 181 host_disconnect(hSession);
174 182
175 - return 0; 183 + return 0;
176 } 184 }
177 185
178 - __declspec (dllexport) int __stdcall hllapi_wait_for_ready(LPWORD rc, WORD seconds) 186 + __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds)
179 { 187 {
180 if(!(wait_for_ready && hSession)) 188 if(!(wait_for_ready && hSession))
181 return EINVAL; 189 return EINVAL;
182 190
183 - *rc = (WORD) wait_for_ready(hSession,(int) seconds); 191 + trace("%s seconds=%d\n", __FUNCTION__, (int) seconds);
184 192
185 - return 0; 193 + return (DWORD) wait_for_ready(hSession,(int) seconds);
186 } 194 }
187 195
188 - __declspec (dllexport) int __stdcall hllapi_wait(LPWORD rc, WORD seconds) 196 + __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds)
189 { 197 {
190 if(!(script_sleep && hSession)) 198 if(!(script_sleep && hSession))
191 return EINVAL; 199 return EINVAL;
192 200
193 - *rc = (WORD) script_sleep(hSession,(int) seconds);  
194 -  
195 - return 0;  
196 - 201 + return (DWORD) script_sleep(hSession,(int) seconds);
197 } 202 }
198 203
199 - __declspec (dllexport) int __stdcall hllapi_get_message_id(LPWORD rc) 204 + __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void)
200 { 205 {
201 if(!(get_message && hSession)) 206 if(!(get_message && hSession))
202 return EINVAL; 207 return EINVAL;
203 - *rc = get_message(hSession);  
204 - return 0; 208 + return (DWORD) get_message(hSession);
205 } 209 }
206 210
207 - __declspec (dllexport) int __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) 211 + __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer)
208 { 212 {
209 char * text; 213 char * text;
210 - int len = strlen(buffer); 214 + int len;
211 215
212 if(!(get_text && release_memory && hSession)) 216 if(!(get_text && release_memory && hSession))
213 return EINVAL; 217 return EINVAL;
214 218
  219 + trace("%s row=%d col=%d buffer=%p",__FUNCTION__,row,col,buffer);
  220 + len = strlen(buffer);
  221 +
  222 + trace(" len=%d",len);
  223 +
215 text = get_text(hSession,row,col,len); 224 text = get_text(hSession,row,col,len);
216 225
  226 + trace(" text=%p errno=%d %s\n",text,errno,strerror(errno));
  227 +
217 if(!text) 228 if(!text)
218 return EINVAL; 229 return EINVAL;
219 230
220 strncpy(buffer,text,len); 231 strncpy(buffer,text,len);
221 release_memory(text); 232 release_memory(text);
222 233
  234 + trace("text:\n%s\n",buffer);
  235 +
223 return 0; 236 return 0;
224 } 237 }
225 238
226 - __declspec (dllexport) int __stdcall hllapi_enter(LPWORD rc) 239 + __declspec (dllexport) DWORD __stdcall hllapi_enter(void)
227 { 240 {
228 if(!(action_enter && hSession)) 241 if(!(action_enter && hSession))
229 return EINVAL; 242 return EINVAL;
230 243
231 - *rc = (WORD) action_enter(hSession);  
232 -  
233 - return 0; 244 + return (DWORD) action_enter(hSession);
234 } 245 }
235 246
236 - __declspec (dllexport) int __stdcall hllapi_set_text_at(LPWORD rc, WORD row, WORD col, LPSTR text) 247 + __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text)
237 { 248 {
238 if(!(set_text_at && hSession)) 249 if(!(set_text_at && hSession))
239 return EINVAL; 250 return EINVAL;
240 251
241 - *rc = (WORD) set_text_at(hSession,row,col,(const unsigned char *) text);  
242 -  
243 - return 0; 252 + return (DWORD) set_text_at(hSession,row,col,(const unsigned char *) text);
244 } 253 }
245 254
246 - __declspec (dllexport) int __stdcall hllapi_cmp_text_at(LPWORD rc, WORD row, WORD col, LPSTR text) 255 + __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text)
247 { 256 {
248 if(!(cmp_text_at && hSession)) 257 if(!(cmp_text_at && hSession))
249 return EINVAL; 258 return EINVAL;
250 259
251 - *rc = (WORD) cmp_text_at(hSession,row,col,(const char *) text);  
252 -  
253 - return 0; 260 + return (DWORD) cmp_text_at(hSession,row,col,(const char *) text);
254 } 261 }
255 262
256 - __declspec (dllexport) int __stdcall hllapi_pfkey(LPWORD rc, WORD key) 263 + __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key)
257 { 264 {
258 if(!(pfkey && hSession)) 265 if(!(pfkey && hSession))
259 return EINVAL; 266 return EINVAL;
260 267
261 - *rc = (WORD) pfkey(hSession,key);  
262 -  
263 - return 0; 268 + return (DWORD) pfkey(hSession,key);
264 } 269 }
265 270
266 - __declspec (dllexport) int __stdcall hllapi_pakey(LPWORD rc, WORD key) 271 + __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key)
267 { 272 {
268 if(!(pfkey && hSession)) 273 if(!(pfkey && hSession))
269 return EINVAL; 274 return EINVAL;
270 275
271 - *rc = (WORD) pakey(hSession,key);  
272 -  
273 - return 0; 276 + return (DWORD) pakey(hSession,key);
274 } 277 }