diff --git a/src/native/private.h b/src/native/private.h index 4c35b26..b31e2eb 100644 --- a/src/native/private.h +++ b/src/native/private.h @@ -100,6 +100,7 @@ DLL_PUBLIC int tn3270_get_program_message(h3270::session *ses); DLL_PUBLIC int tn3270_get_secure(h3270::session *ses); + DLL_PUBLIC int tn3270_get_contents(h3270::session *ses, char* str, int strlen); DLL_PUBLIC int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen); DLL_PUBLIC int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int strlen); diff --git a/src/native/screen.cc b/src/native/screen.cc index 7e2bea1..1246048 100644 --- a/src/native/screen.cc +++ b/src/native/screen.cc @@ -31,6 +31,21 @@ /*---[ Implement ]----------------------------------------------------------------------------------*/ +int tn3270_get_contents(h3270::session *ses, char* str, int sz) { + + std::string contents = ses->get_contents(); + + memset(str,0,sz); + strncpy(str,contents.c_str(),sz); + if(contents.size() < ((size_t) sz)) { + str[contents.size()] = 0; + return contents.size(); + } + + return sz; + +} + int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen) { memset(str,0,strlen); strncpy(str,ses->get_string(addr,strlen).c_str(),strlen); @@ -38,10 +53,8 @@ int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen) { } int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int sz) { - memset(str,0,sz); + memset(str,0,sz+1); strncpy(str,ses->get_string_at(row,col,sz).c_str(),sz); - str[sz] = 0; - debug("%s(%d,%d) len=%u (Required=%d)\n",__FUNCTION__,row,col,(unsigned int) strlen(str), sz); return (int) strlen(str); } diff --git a/src/pw3270-sharp/pw3270-sharp.cs b/src/pw3270-sharp/pw3270-sharp.cs index 5ad322f..060f922 100644 --- a/src/pw3270-sharp/pw3270-sharp.cs +++ b/src/pw3270-sharp/pw3270-sharp.cs @@ -87,6 +87,9 @@ namespace pw3270 { extern static int tn3270_get_secure(IntPtr Session); [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_contents(IntPtr Session, StringBuilder str, int strlen); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] extern static int tn3270_get_string(IntPtr Session, int addr, StringBuilder str, int strlen); [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] @@ -275,6 +278,22 @@ namespace pw3270 { } /// + /// Get contents + /// + /// + /// + /// Contents from terminal screen. + /// + /// + public override string ToString() { + int strlen = (tn3270_get_width(hSession)+1) * (tn3270_get_height(hSession)+1); + StringBuilder str = new StringBuilder(strlen+1); + strlen = tn3270_get_contents(hSession, str, strlen); + return str.ToString(); + } + + + /// /// Get contents at address /// /// @@ -288,7 +307,7 @@ namespace pw3270 { public string GetString(int addr, int strlen) { StringBuilder str = new StringBuilder(strlen+1); tn3270_get_string(hSession, addr, str, strlen); - return str.ToString(0,strlen); + return str.ToString(); } /// diff --git a/testprograms/sample.cs b/testprograms/sample.cs index 8551cc7..2df6141 100644 --- a/testprograms/sample.cs +++ b/testprograms/sample.cs @@ -38,6 +38,7 @@ class sample { System.Console.WriteLine("Using pw3270 version " + host.Version + " revision " + host.Revision); System.Console.WriteLine("Screen size is " + host.Width + "x" + host.Height + " (" + host.Length + ")"); + // host.Connect("tn3270://zos.efglobe.com:telnet",10); host.Connect("tn3270://zos.efglobe.com:telnet",10); if(host.Connected) { @@ -46,7 +47,7 @@ class sample { System.Console.WriteLine("Wait for ready returned " + host.WaitForReady(5)); - System.Console.WriteLine(host.GetStringAt(14,19,38)); + System.Console.WriteLine(host); host.Disconnect(); } -- libgit2 0.21.2