Commit 0e3d730ada9f89651598638a8e393a3be24c68d8

Authored by perry.werneck@gmail.com
1 parent f58e1770

Melhorando macros para StarBasic/VB

@@ -247,6 +247,7 @@ @@ -247,6 +247,7 @@
247 <Unit filename="src/plugins/remotectl/calls.c"> 247 <Unit filename="src/plugins/remotectl/calls.c">
248 <Option compilerVar="CC" /> 248 <Option compilerVar="CC" />
249 </Unit> 249 </Unit>
  250 + <Unit filename="src/plugins/remotectl/client.h" />
250 <Unit filename="src/plugins/remotectl/hllapi.c"> 251 <Unit filename="src/plugins/remotectl/hllapi.c">
251 <Option compilerVar="CC" /> 252 <Option compilerVar="CC" />
252 </Unit> 253 </Unit>
src/include/pw3270/hllapi.h
@@ -85,9 +85,10 @@ extern &quot;C&quot; { @@ -85,9 +85,10 @@ extern &quot;C&quot; {
85 85
86 __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void); 86 __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void);
87 87
88 - __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri); 88 + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait);
89 __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void); 89 __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
90 __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void); 90 __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
  91 + __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void);
91 __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer); 92 __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
92 __declspec (dllexport) DWORD __stdcall hllapi_enter(void); 93 __declspec (dllexport) DWORD __stdcall hllapi_enter(void);
93 __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text); 94 __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text);
src/plugins/remotectl/calls.c
@@ -36,6 +36,9 @@ @@ -36,6 +36,9 @@
36 #include <stdio.h> 36 #include <stdio.h>
37 #include <lib3270/log.h> 37 #include <lib3270/log.h>
38 #include "client.h" 38 #include "client.h"
  39 +
  40 + #undef trace
  41 + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } }
39 42
40 /*--[ Globals ]--------------------------------------------------------------------------------------*/ 43 /*--[ Globals ]--------------------------------------------------------------------------------------*/
41 44
@@ -46,6 +49,7 @@ @@ -46,6 +49,7 @@
46 static void (*session_free)(void *h) = NULL; 49 static void (*session_free)(void *h) = NULL;
47 static const char * (*get_revision)(void) = NULL; 50 static const char * (*get_revision)(void) = NULL;
48 static int (*host_connect)(void *h,const char *n, int wait) = NULL; 51 static int (*host_connect)(void *h,const char *n, int wait) = NULL;
  52 + static int (*host_is_connected)(void *h) = NULL;
49 static int (*wait_for_ready)(void *h, int seconds) = NULL; 53 static int (*wait_for_ready)(void *h, int seconds) = NULL;
50 static void (*host_disconnect)(void *h) = NULL; 54 static void (*host_disconnect)(void *h) = NULL;
51 static int (*script_sleep)(void *h, int seconds) = NULL; 55 static int (*script_sleep)(void *h, int seconds) = NULL;
@@ -70,8 +74,9 @@ @@ -70,8 +74,9 @@
70 { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, 74 { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" },
71 { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, 75 { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" },
72 { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, 76 { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" },
73 - { (void **) &wait_for_ready, (void *) NULL, "lib3270_wait_for_ready" },  
74 - { (void **) &script_sleep, (void *) NULL, "lib3270_wait" }, 77 + { (void **) &host_is_connected, (void *) NULL, "lib3270_in_tn3270e" },
  78 + { (void **) &wait_for_ready, (void *) NULL, "lib3270_wait_for_ready" },
  79 + { (void **) &script_sleep, (void *) NULL, "lib3270_wait" },
75 { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, 80 { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" },
76 { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, 81 { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" },
77 { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, 82 { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" },
@@ -98,9 +103,21 @@ @@ -98,9 +103,21 @@
98 103
99 trace("%s(%s)",__FUNCTION__,(char *) mode); 104 trace("%s(%s)",__FUNCTION__,(char *) mode);
100 105
101 - if(!(mode && *mode)) 106 + if(mode && *mode)
  107 + {
  108 + // Get pointers to the pipe based calls
  109 + int f;
  110 +
  111 + trace("%s: Loading pipe based calls",__FUNCTION__);
  112 + for(f=0;entry_point[f].name;f++)
  113 + *entry_point[f].call = entry_point[f].pipe;
  114 +
  115 + }
  116 + else
102 { 117 {
103 // Direct mode, load lib3270.dll, get pointers to the calls 118 // Direct mode, load lib3270.dll, get pointers to the calls
  119 + static const char *dllname = "lib3270.dll." PACKAGE_VERSION;
  120 +
104 int f; 121 int f;
105 HKEY hKey = 0; 122 HKEY hKey = 0;
106 HMODULE kernel; 123 HMODULE kernel;
@@ -109,11 +126,13 @@ @@ -109,11 +126,13 @@
109 HANDLE (*AddDllDirectory)(PCWSTR NewDirectory); 126 HANDLE (*AddDllDirectory)(PCWSTR NewDirectory);
110 BOOL (*RemoveDllDirectory)(HANDLE Cookie); 127 BOOL (*RemoveDllDirectory)(HANDLE Cookie);
111 UINT errorMode; 128 UINT errorMode;
  129 + char datadir[4096];
112 130
113 trace("hModule=%p",hModule); 131 trace("hModule=%p",hModule);
114 if(hModule) 132 if(hModule)
115 return EBUSY; 133 return EBUSY;
116 134
  135 + *datadir = 0;
117 kernel = LoadLibrary("kernel32.dll"); 136 kernel = LoadLibrary("kernel32.dll");
118 AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); 137 AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
119 RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); 138 RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
@@ -123,27 +142,41 @@ @@ -123,27 +142,41 @@
123 142
124 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) 143 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
125 { 144 {
126 - char data[4096];  
127 - unsigned long datalen = sizeof(data); // data field length(in), data returned length(out) 145 + unsigned long datalen = sizeof(datadir); // data field length(in), data returned length(out)
128 unsigned long datatype; // #defined in winnt.h (predefined types 0-11) 146 unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
129 - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) data,&datalen) == ERROR_SUCCESS) 147 + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) == ERROR_SUCCESS)
130 { 148 {
131 // Datadir is set, add it to DLL load path 149 // Datadir is set, add it to DLL load path
132 wchar_t path[4096]; 150 wchar_t path[4096];
133 - mbstowcs(path, data, 4095);  
134 - trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",data,AddDllDirectory,RemoveDllDirectory); 151 + mbstowcs(path, datadir, 4095);
  152 + trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory);
135 if(AddDllDirectory) 153 if(AddDllDirectory)
136 cookie = AddDllDirectory(path); 154 cookie = AddDllDirectory(path);
137 } 155 }
138 RegCloseKey(hKey); 156 RegCloseKey(hKey);
139 } 157 }
140 158
141 - hModule = LoadLibraryEx("lib3270.dll.5.0",NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); 159 +// hModule = LoadLibraryEx("lib3270.dll.5.0",NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
  160 + hModule = LoadLibrary(dllname);
142 rc = GetLastError(); 161 rc = GetLastError();
143 - trace("hModule=%p rc=%d",hModule,(int) rc);  
144 162
145 SetErrorMode(errorMode); 163 SetErrorMode(errorMode);
146 164
  165 + trace("%s hModule=%p rc=%d",dllname,hModule,(int) rc);
  166 +
  167 + if(rc == ERROR_MOD_NOT_FOUND && *datadir)
  168 + {
  169 + char buffer[4096];
  170 +#ifdef DEBUG
  171 + snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname);
  172 +#else
  173 + snprintf(buffer,4096,"%s\\%s",datadir,dllname);
  174 +#endif // DEBUG
  175 +
  176 + hModule = LoadLibrary(buffer);
  177 + trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc);
  178 + }
  179 +
147 if(cookie && RemoveDllDirectory) 180 if(cookie && RemoveDllDirectory)
148 RemoveDllDirectory(cookie); 181 RemoveDllDirectory(cookie);
149 182
@@ -170,16 +203,6 @@ @@ -170,16 +203,6 @@
170 } 203 }
171 204
172 } 205 }
173 - else  
174 - {  
175 - // Get pointers to the pipe based calls  
176 - int f;  
177 -  
178 - for(f=0;entry_point[f].name;f++)  
179 - *entry_point[f].call = entry_point[f].pipe;  
180 -  
181 - }  
182 -  
183 // Get session handle 206 // Get session handle
184 hSession = session_new((const char *) mode); 207 hSession = session_new((const char *) mode);
185 trace("%s ok hSession=%p\n",__FUNCTION__,hSession); 208 trace("%s ok hSession=%p\n",__FUNCTION__,hSession);
@@ -214,12 +237,20 @@ @@ -214,12 +237,20 @@
214 return (DWORD) atoi(get_revision()); 237 return (DWORD) atoi(get_revision());
215 } 238 }
216 239
217 - __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri) 240 + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait)
218 { 241 {
219 if(!(host_connect && hSession && uri)) 242 if(!(host_connect && hSession && uri))
220 return EINVAL; 243 return EINVAL;
221 244
222 - return host_connect(hSession,uri,0); 245 + return host_connect(hSession,uri,wait);
  246 + }
  247 +
  248 + __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void)
  249 + {
  250 + if(!(host_is_connected && hSession))
  251 + return EINVAL;
  252 +
  253 + return host_is_connected(hSession);
223 } 254 }
224 255
225 __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void) 256 __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void)
src/plugins/remotectl/hllapi.c
@@ -47,9 +47,54 @@ @@ -47,9 +47,54 @@
47 LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) 47 LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc)
48 #endif // _WIN32 48 #endif // _WIN32
49 { 49 {
  50 + switch(*func)
  51 + {
  52 + case HLLAPI_CMD_CONNECTPS:
  53 + break;
50 54
  55 + case HLLAPI_CMD_DISCONNECTPS:
  56 + break;
51 57
52 - return -1; 58 + case HLLAPI_CMD_INPUTSTRING:
  59 + break;
  60 +
  61 + case HLLAPI_CMD_WAIT:
  62 + break;
  63 +
  64 + case HLLAPI_CMD_COPYPS:
  65 + break;
  66 +
  67 + case HLLAPI_CMD_SEARCHPS:
  68 + break;
  69 +
  70 + case HLLAPI_CMD_QUERYCURSOR:
  71 + break;
  72 +
  73 + case HLLAPI_CMD_COPYPSTOSTR:
  74 + break;
  75 +
  76 + case HLLAPI_CMD_COPYSTRTOPS:
  77 + break;
  78 +
  79 + case HLLAPI_CMD_SETCURSOR:
  80 + break;
  81 +
  82 + case HLLAPI_CMD_SENDFILE:
  83 + break;
  84 +
  85 + case HLLAPI_CMD_RECEIVEFILE:
  86 + break;
  87 +
  88 + case HLLAPI_CMD_GETREVISION:
  89 + break;
  90 +
  91 + default:
  92 + *rc = EINVAL;
  93 + return EINVAL;
  94 + }
  95 +
  96 +
  97 + return 0;
53 } 98 }
54 99
55 /* 100 /*
src/plugins/remotectl/remote.c 0 → 100644
@@ -0,0 +1,242 @@ @@ -0,0 +1,242 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como calls.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <lib3270.h>
  31 + #include <malloc.h>
  32 + #include <string.h>
  33 + #include <errno.h>
  34 + #include <stdio.h>
  35 + #include <lib3270/log.h>
  36 +
  37 + #include "client.h"
  38 + #include "packets.h"
  39 +
  40 +/*--[ Globals ]--------------------------------------------------------------------------------------*/
  41 +
  42 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  43 +
  44 + void * hllapi_pipe_init(const char *id)
  45 + {
  46 + HANDLE hPipe = INVALID_HANDLE_VALUE;
  47 + static DWORD dwMode = PIPE_READMODE_MESSAGE;
  48 + char buffer[4096];
  49 + char * name = strdup(id);
  50 + char * ptr;
  51 +
  52 + trace("%s(%s)",__FUNCTION__,id);
  53 +
  54 + for(ptr=name;*ptr;ptr++)
  55 + {
  56 + if(*ptr == ':')
  57 + *ptr = '_';
  58 + }
  59 +
  60 + snprintf(buffer,4095,"\\\\.\\pipe\\%s",name);
  61 +
  62 + free(name);
  63 +
  64 + trace("Opening \"%s\"",buffer);
  65 +
  66 + if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT))
  67 + {
  68 + trace("%s: Pipe not found",__FUNCTION__);
  69 + errno = ENOENT;
  70 + return NULL;
  71 + }
  72 +
  73 + hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
  74 +
  75 + if(hPipe == INVALID_HANDLE_VALUE)
  76 + {
  77 + errno = GetLastError();
  78 + return NULL;
  79 + }
  80 +
  81 + if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL))
  82 + {
  83 + errno = GetLastError();
  84 + return NULL;
  85 + }
  86 +
  87 + trace("hPipe=%p",(void *) hPipe);
  88 + return hPipe;
  89 + }
  90 +
  91 + void hllapi_pipe_deinit(void *h)
  92 + {
  93 + trace("%s(%p)",__FUNCTION__,h);
  94 +
  95 + if(!h)
  96 + return;
  97 +
  98 + CloseHandle((HANDLE) h);
  99 + }
  100 +
  101 + const char * hllapi_pipe_get_revision(void)
  102 + {
  103 + return PACKAGE_REVISION;
  104 + }
  105 +
  106 + int hllapi_pipe_connect(void *h, const char *n, int wait)
  107 + {
  108 + struct hllapi_packet_connect * pkt;
  109 + struct hllapi_packet_result response;
  110 + DWORD cbSize;
  111 +
  112 + if(!n)
  113 + n = "";
  114 +
  115 + cbSize = sizeof(struct hllapi_packet_connect)+strlen(n);
  116 + pkt = malloc(cbSize);
  117 +
  118 + pkt->packet_id = HLLAPI_PACKET_CONNECT;
  119 + pkt->wait = (unsigned char) wait;
  120 + strcpy(pkt->hostname,n);
  121 +
  122 + trace("Sending %s",pkt->hostname);
  123 +
  124 + if(!TransactNamedPipe((HANDLE) h,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL))
  125 + {
  126 + errno = GetLastError();
  127 + response.rc = -1;
  128 + }
  129 +
  130 + free(pkt);
  131 +
  132 + return response.rc;
  133 + }
  134 +
  135 + void hllapi_pipe_disconnect(void *h)
  136 + {
  137 + static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT };
  138 + struct hllapi_packet_result response;
  139 + DWORD cbSize = sizeof(query);
  140 + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  141 + }
  142 +
  143 + LIB3270_MESSAGE hllapi_pipe_get_message(void *h)
  144 + {
  145 + static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_PROGRAM_MESSAGE };
  146 + struct hllapi_packet_result response;
  147 + DWORD cbSize = sizeof(query);
  148 + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  149 + return (LIB3270_MESSAGE) response.rc;
  150 + }
  151 +
  152 + char * hllapi_pipe_get_text_at(void *h, int row, int col, int len)
  153 + {
  154 + struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, };
  155 + struct hllapi_packet_text * response;
  156 + DWORD cbSize = sizeof(struct hllapi_packet_text)+len;
  157 + char * text = NULL;
  158 +
  159 + response = malloc(cbSize+2);
  160 + memset(response,0,cbSize+2);
  161 +
  162 + if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL))
  163 + return NULL;
  164 +
  165 + if(response->packet_id)
  166 + errno = response->packet_id;
  167 + else
  168 + text = strdup(response->text);
  169 +
  170 + free(response);
  171 + return text;
  172 + }
  173 +
  174 + int hllapi_pipe_enter(void *h)
  175 + {
  176 + static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER };
  177 + struct hllapi_packet_result response;
  178 + DWORD cbSize = sizeof(query);
  179 + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  180 + return response.rc;
  181 + }
  182 +
  183 + int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str)
  184 + {
  185 + struct hllapi_packet_text_at * query;
  186 + struct hllapi_packet_result response;
  187 + DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str);
  188 +
  189 + query = malloc(cbSize);
  190 + query->packet_id = HLLAPI_PACKET_SET_TEXT_AT;
  191 + query->row = row;
  192 + query->col = col;
  193 + strcpy(query->text,(const char *) str);
  194 +
  195 + TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
  196 +
  197 + free(query);
  198 +
  199 + return response.rc;
  200 + }
  201 +
  202 + int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text)
  203 + {
  204 + struct hllapi_packet_text_at * query;
  205 + struct hllapi_packet_result response;
  206 + DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text);
  207 +
  208 + query = malloc(cbSize);
  209 + query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT;
  210 + query->row = row;
  211 + query->col = col;
  212 + strcpy(query->text,text);
  213 +
  214 + TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
  215 +
  216 + free(query);
  217 +
  218 + return response.rc;
  219 + }
  220 +
  221 + int hllapi_pipe_pfkey(void *h, int key)
  222 + {
  223 + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, key };
  224 + struct hllapi_packet_result response;
  225 + DWORD cbSize = sizeof(query);
  226 + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  227 + return response.rc;
  228 + }
  229 +
  230 + int hllapi_pipe_pakey(void *h, int key)
  231 + {
  232 + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, key };
  233 + struct hllapi_packet_result response;
  234 + DWORD cbSize = sizeof(query);
  235 + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  236 + return response.rc;
  237 + }
  238 +
  239 + void hllapi_pipe_release_memory(void *p)
  240 + {
  241 + free(p);
  242 + }