如何从Java访问VB DLL?

如何从Java访问VB DLL?,java,dll,jna,Java,Dll,Jna,我有一些VB程序使用过的.dll文件,现在我必须用java移植应用程序,但是.dll文件提供程序没有为java平台提供任何JAR或API。 既然我的要求是访问java类中那些.dll文件中编写的代码,那么有没有办法访问.dll thasks提前…:) 我也有一个解决办法 package jnahelloworldtest; import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLong;

我有一些VB程序使用过的.dll文件,现在我必须用java移植应用程序,但是.dll文件提供程序没有为java平台提供任何JAR或API。 既然我的要求是访问java类中那些.dll文件中编写的代码,那么有没有办法访问.dll

thasks提前…:)

我也有一个解决办法

package jnahelloworldtest;


import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.*;

/** Simple example of native library declaration and usage. */
public class Main {
    public interface simpleDLL extends Library {
        simpleDLL INSTANCE = (simpleDLL) Native.loadLibrary(
            (Platform.isWindows() ? "simpleDLL" : "simpleDLLLinuxPort"), simpleDLL.class);
        // it's possible to check the platform on which program runs, for example purposes we assume that there's a linux port of the library (it's not attached to the downloadable project)
        byte giveVoidPtrGetChar(Pointer param); // char giveVoidPtrGetChar(void* param);
        int giveVoidPtrGetInt(Pointer param);   //int giveVoidPtrGetInt(void* param);
        int giveIntGetInt(int a);               // int giveIntGetInt(int a);
        void simpleCall();                      // void simpleCall();
    }

    public static void main(String[] args) {

        simpleDLL sdll = simpleDLL.INSTANCE;

        sdll.simpleCall();  // call of void function

        int a = 3;
        int result1 = sdll.giveIntGetInt(a);  // calling function with int parameter&result
        System.out.println("giveIntGetInt("+a+"): " + result1);

        String testStr = "ToBeOrNotToBe";
        Memory mTest = new Memory(testStr.length()+1);  // '+1' remember about extra byte for \0 character!
        mTest.setString(0, testStr);
        String testReturn = mTest.getString(0); // you can see that String got properly stored in Memory object
        System.out.println("String in Memory:"+testReturn);

        Memory intMem = new Memory(4);  // allocating space
        intMem.setInt(0, 666); // setting allocated memory to an integer
        Pointer intPointer = intMem.getPointer(0);

        int int1 = sdll.giveVoidPtrGetInt(Pointer.NULL); // passing null, getting default result
        System.out.println("giveVoidPtrGetInt(null):" + int1); // passing int stored in Memory object, getting it back
        int int2 = sdll.giveVoidPtrGetInt(intMem);
       //int int2 = sdll.giveVoidPtrGetInt(intPointer);  causes JVM crash, use memory object directly!
        System.out.println("giveVoidPtrGetInt(666):" + int2);

        byte char1 = sdll.giveVoidPtrGetChar(Pointer.NULL);  // passing null, getting default result
        byte char2 = sdll.giveVoidPtrGetChar(mTest);        // passing string stored in Memory object, getting first letter

        System.out.println("giveVoidPtrGetChar(null):" + (char)char1);
        System.out.println("giveVoidPtrGetChar('ToBeOrNotToBe'):" + (char)char2);

    }
}
但这并不能帮我解决问题。

您可以使用它来确定从DLL导出哪些函数

VB使用stdcall调用约定,因此您需要从
StdCallLibrary
扩展而不是
Library
,并且您可能需要使用初始化库,因为DLL的导出方法可能会用
@NN
后缀装饰方法名称

Map options = new Map();
options.put(Library.OPTION_FUNCTION_MAPPER, new StdCallFunctionMapper());
SimpleDLL dll = (SimpleDLL)Native.loadLibrary("simpleDLL", SimpleDLL.class, options);

我必须使用放在c驱动器中的abc.dll它应该做什么,它在做什么?dll文件就像.net或VB编程中的jar,它们只是APISo,它应该做什么,它在做什么?