diff --git a/src/classlib/remote.cc b/src/classlib/remote.cc index 2f27cad..aa00bda 100644 --- a/src/classlib/remote.cc +++ b/src/classlib/remote.cc @@ -408,6 +408,34 @@ } #endif // HAVE_DBUS +#if defined(WIN32) + + static string getRegistryKey(const char *name) throw (std::exception) + { + char buffer[4096]; + HKEY hKey = 0; + unsigned long datalen = sizeof(buffer); + + *buffer = 0; + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) + { + throw exception("Can't open key %s","HKLM\\Software\\pw3270"); + } + else + { + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) + + if(RegQueryValueExA(hKey,name,NULL,&datatype,(LPBYTE) buffer,&datalen) != ERROR_SUCCESS) + *buffer = 0; + RegCloseKey(hKey); + } + + return string(buffer); + + } + +#endif // defined + remote(const char *session) throw (std::exception) { #if defined(WIN32) @@ -415,51 +443,36 @@ char buffer[4096]; char * str; char * ptr; - time_t timer; + time_t timer = time(0)+1; hPipe = INVALID_HANDLE_VALUE; if(strcasecmp(session,"start") == 0 || strcasecmp(session,"new") == 0) { // Start a new session + string appName = getRegistryKey("appName"); char buffer[80]; - char appName[4096]; - HKEY hKey = 0; - unsigned long datalen = 4096; STARTUPINFO si; PROCESS_INFORMATION pi; // Get application path - *appName = 0; - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) - { - throw exception("Can't open key %s","HKLM\\Software\\pw3270"); - return; - } - else - { - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) - if(RegQueryValueExA(hKey,"appName",NULL,&datatype,(LPBYTE) appName,&datalen) != ERROR_SUCCESS) - *appName = 0; - RegCloseKey(hKey); - } - if(!*appName) + if(!appName.size()) { throw exception("key %s\\appName is invalid","HKLM\\Software\\pw3270"); return; } - trace("%s appname=%s\n",__FUNCTION__,appName); + trace("%s appname=%s\n",__FUNCTION__,appName.c_str()); - snprintf(buffer,79,"%s --session=\"H%06d\"",appName,getpid()); + snprintf(buffer,79,"%s --session=\"H%06d\"",appName.c_str(),getpid()); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // si.dwFlags = STARTF_PREVENTPINNING; - trace("App: %s",appName); + trace("App: %s",appName.c_str()); trace("CmdLine: %s",buffer); if(CreateProcess(NULL,buffer,NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) @@ -469,13 +482,16 @@ } else { - throw exception("Can't start %s",appName); + throw exception("Can't start %s",appName.c_str()); return; } snprintf(buffer,4095,"H%06d_a",getpid()); str = strdup(buffer); + // Até 20 segundos para o processo iniciar. + timer = time(0)+20; + } else { @@ -490,6 +506,15 @@ else *ptr = tolower(*ptr); } + + // Wait? + int delay = atoi(getRegistryKey("hllapiWait").c_str()); + + if(delay) { + timer = time(0) + delay; + } + + } snprintf(buffer,4095,"\\\\.\\pipe\\%s",str); @@ -502,11 +527,11 @@ if(hPipe == INVALID_HANDLE_VALUE) { - timer = time(0)+20; + // Cant get session, wait. while(hPipe == INVALID_HANDLE_VALUE && time(0) < timer) { hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); - Sleep(10); + Sleep(1); } } diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h index d1da897..157af09 100644 --- a/src/include/pw3270/hllapi.h +++ b/src/include/pw3270/hllapi.h @@ -33,6 +33,7 @@ #define HLLAPI_H_INCLUDED 1 #include + #include #ifdef __cplusplus extern "C" { @@ -101,12 +102,21 @@ extern "C" { #define HLLAPI_STATUS_WAITING HLLAPI_STATUS_TIMEOUT - #ifdef WIN32 + #if defined(WIN32) + #include // http://www.mingw.org/wiki/Visual_Basic_DLL #define HLLAPI_API_CALL __declspec (dllexport) DWORD __stdcall + #else + + #define HLLAPI_API_CALL __attribute__((visibility("default"))) extern + #define WORD uint32_t + #define LPWORD uint32_t * + #define LPSTR char * + #define HANDLE int + #endif // WIN32 HLLAPI_API_CALL hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc); diff --git a/src/plugins/hllapi/Makefile.in b/src/plugins/hllapi/Makefile.in index d8d654a..42c4794 100644 --- a/src/plugins/hllapi/Makefile.in +++ b/src/plugins/hllapi/Makefile.in @@ -29,7 +29,7 @@ #---[ Sources ]---------------------------------------------------------------- MODULE_NAME=hllapi -DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile +DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile ../../classlib/*.cc PLUGIN_SRC=pluginmain.c EXTAPI_SRC=calls.c hllapi.c @@ -64,5 +64,11 @@ $(BINDBG)/$(PLUGIN_NAME): $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$( $(BINDBG)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC)), $(OBJDBG)/$(SRC)@OBJEXT@) $(CLASS_DEBUG_OBJECTS) @echo " CCLD `basename $@`" @$(MKDIR) `dirname $@` - @$(CXX) $(SYSDLL_FLAGS) $(LDFLAGS) @LDSOFLAGS@ @DBGRPATH@ -o $@ $^ $(CLASS_LIBS) + @$(CXX) $(SYSDLL_FLAGS) $(LDFLAGS) @LDSOFLAGS@ @DBGRPATH@ -L../../../.bin/Debug -o $@ $^ $(CLASS_LIBS) +test: $(BINDBG)/test@EXEEXT@ + +$(BINDBG)/test@EXEEXT@: $(BINDBG)$(DLL_NAME).$(VERSION) $(OBJDBG)/testprogram.o + @echo " CCLD `basename $@`" + @$(MKDIR) `dirname $@` + @$(LD) -o $@ $^ $(LIBS) $(BINDBG)$(DLL_NAME).$(VERSION) diff --git a/src/plugins/hllapi/hllapi.cbp b/src/plugins/hllapi/hllapi.cbp index 9407108..4c6f0d8 100644 --- a/src/plugins/hllapi/hllapi.cbp +++ b/src/plugins/hllapi/hllapi.cbp @@ -62,6 +62,12 @@ + + + + + + @@ -71,9 +77,6 @@ - - diff --git a/src/plugins/hllapi/pluginmain.c b/src/plugins/hllapi/pluginmain.c index 0211cde..7524bc4 100644 --- a/src/plugins/hllapi/pluginmain.c +++ b/src/plugins/hllapi/pluginmain.c @@ -32,7 +32,11 @@ */ #include "server.h" + +#ifdef _WIN32 #include +#endif // _WIN32 + #include #include #include -- libgit2 0.21.2