Java DLL功能:连接MicroFocus Rumba ehlapi32

本文关键字:MicroFocus Rumba ehlapi32 连接 DLL 功能 Java | 更新日期: 2023-09-27 18:10:32

我有一个问题,我一直试图解决几个月了。我正在尝试使用Java中的ehlapi32.dll库连接到MicroFocus Rumba。网上关于Java的参考资料并不多。我尝试使用JNA加载它们,但我继续收到"1"状态,这意味着给出的过程是不正确的。我不确定这是否是正确声明函数或可能是过程的问题。我通过使用windows cmd"任务列表"并找到我的wddsppage .bin PID手动提供了processID。

我写过很多VB程序,和下面的程序连接得很好:

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

我的问题可能是过程,在VB中我像这样声明:

Declare Function GetCurrentProcessId Lib "kernel32" () As Long

所以我想知道我的进程是否被正确声明?我是否可以手动进入测试流程?我想我需要"找到"Rumba进程,但下面的代码似乎给了我JVM正在使用的进程?

    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  
        */
    }

最后,预期结果应该是' 0 ',如Java注释中提供的那样。提前感谢。库加载良好,我在Eclipse中通过Eclipse -> Windows -> Pref -> Java -> Installed JREs -> Edit Default JRE ->设置路径,并输入"- djava .library.path=C:'Windows'System32;C:'Rumba'system",所以我不认为加载库是一个问题。

编辑:

另外,上面的VB代码是在MSAccess和MS Excel中使用的,所以可能是默认加载了参考库,它只是简单地使用函数声明。特别是这个:

Declare Function WD_ConnectPS Lib "Ehlapi32.DLL" (ByVal hInstance As Long, ByVal ShortName As String) As Integer

只有实例和Rumba窗口(在本例中为"A")被传递,然后它返回一个状态'0',这意味着它是活动的和准备好的,或者其他一些代码(参见代码注释)。

Java DLL功能:连接MicroFocus Rumba ehlapi32

我找到了问题所在。事实证明hInstance需要声明为'int'而不是'long '。在我继续摆弄代码之后,我终于能够从Java通信并发送一个字符串。代码如下,以防有人想要它作为一个例子。它是连接和发送字符串的实际工作代码。您可以使用下面的代码轻松地添加所有EHLAPI函数:

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  
    */
}

使用http://www.codeproject.com/Articles/9615/Using-EHLLAPI-in-C作为示例,使用c# . net更容易做到这一点。由于c#和Java非常相似,您可以查看一下。此外,您还可以使用Java . net库来辅助模拟c#程序。另一种方法(但不是首选)是使用vb运行shell脚本来抓取,同时使用Java作为图形界面。如果数据相当大,并且可以从文本文件存储到矢量文件,那么这种方法就可以很好地工作。