I have an issue that I've been trying to solve for months now. I am trying to connect to MicroFocus Rumba using the ehlapi32.dll library in Java. There are not many references online for Java. I have tried loading them using JNA, but i continue receiving a '1' status which means the process given is incorrect. I am not sure if this is an issue of declaring the function correctly or possibly the process. I have manually provided the processID by using windows cmd 'tasklist' and finding my WDDspPag.bin PID.
I have written many VB programs and connect just fine with the following:
Declare Function WD_ConnectPS Lib "Ehlapi32.DLL" (ByVal hInstance As Long, ByVal ShortName As String) As Integer
Declare Function WD_CopyPSToString Lib "Ehlapi32.DLL" (ByVal hInstance As Long, ByVal Position As Integer, ByVal Buffer As String, ByVal length As Integer) As Integer
Declare Function WD_CopyStringToPS Lib "Ehlapi32.DLL" (ByVal hInstance As Long, ByVal Position As Integer, ByVal Buffer As String, ByVal length As Integer) As Integer
Declare Function WD_SendKey Lib "Ehlapi32.DLL" (ByVal hInstance As Long, ByVal KeyData As String) As Integer
Declare Function WD_DisconnectPS Lib "Ehlapi32.DLL" (ByVal hInstance As Long) As Integer
My issue could be the process, which in VB i declare like this:
Declare Function GetCurrentProcessId Lib "kernel32" () As Long
So I would like to know if my process is being declared correctly? If I can manually enter the process for testing purposes? I suppose i need to "find" the Rumba process, but the below code seems to give me the process which JVM is using?
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.platform.win32.Kernel32;
public class RumbaConnect {
public interface ehlapi32 extends Library {
ehlapi32 ehlapi32 = (ehlapi32) Native.loadLibrary(
(Platform.isWindows() ? "ehlapi32" : "ehlapi32"), ehlapi32.class);
public int WD_ConnectPS(long hInstance , String ShortName);
public int WD_DisconnectPS(long hInstance);
}
public static final ehlapi32 ehlapi32 = (ehlapi32) Native.loadLibrary("ehlapi32", ehlapi32.class);
public static final Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
public static void main(String[] args) {
int process = 0;
int status = 0;
process = kernel32.GetCurrentProcessId();
status = ehlapi32.WD_ConnectPS(process, "a");
// status = getProcAddress.WD_ConnectPS(5976, "A");
System.out.println("Your Rumba Status: " + status);
}
/* 0 The function was successful
1 An incorrect PSID was specified
8 No prior call to Start Communication Notification (80) function was called for the PSID
9 A system error was encountered
*/
}
Finally, the expected result should be 'zero,' as provided in the Java comments. Thanks in advance. The libraries load fine, i set the path in Eclipse via Eclipse -> Windows -> Pref -> Java -> Installed JREs -> Edit Default JRE -> and entered "-Djava.library.path=C:\Windows\System32;C:\Rumba\system" So i don't believe loading the libraries is an issue.
Edit:
Additionally, the VB code above is used in MSAccess and MS Excel, so it could be that there are reference libraries loaded by default and it simply works with a simply declaration of a function. Specifically this:
Declare Function WD_ConnectPS Lib "Ehlapi32.DLL" (ByVal hInstance As Long, ByVal ShortName As String) As Integer
Only the instance and the Rumba window (in this case "A") is passed, then it returns a status of either '0' which means its active and ready, or some other code (see code comments).
I figured out the problem. It turns out the hInstance needs to be declared as 'int' and not 'long.' After i continued playing around with the code i finally was able to communicate from Java and send a string. The code is below in case anyone would like it as an example. It is actual working code that connects and sends a string. You are able to add all of the EHLAPI functions with ease with this code below:
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.platform.win32.Kernel32;
public class RumbaConnect {
public interface ehlapi32 extends Library {
ehlapi32 ehlapi32 = (ehlapi32) Native.loadLibrary(
(Platform.isWindows() ? "ehlapi32" : "ehlapi32"), ehlapi32.class);
public int WD_ConnectPS(int hInstance , String ShortName);
public int WD_SendKey(int hInstance, String KeyData);
}
public static final ehlapi32 ehlapi32 = (ehlapi32) Native.loadLibrary("ehlapi32", ehlapi32.class);
public static final Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
public static void main(String[] args) {
int process = 0;
int status = 0;
int intResult = 0;
process = kernel32.GetCurrentProcessId();
status = ehlapi32.WD_ConnectPS(process, "A");
intResult = ehlapi32.WD_SendKey(process, "MYNAME");
System.out.println("Your Rumba Status: " + status);
}
/* 0 The function was successful
1 An incorrect PSID was specified
8 No prior call to Start Communication Notification (80) function was called for the PSID
9 A system error was encountered
*/
}