call c++ function in Java with input and output arguments

后端 未结 1 1087
[愿得一人]
[愿得一人] 2021-01-26 10:21

I have a c++ code which has been connected to a visual basic user interface by someone else. Here is one of the functions code that connects c++ to visual basic:



        
相关标签:
1条回答
  • 2021-01-26 11:18

    Here is an instructional example to help get you started. In this snippet, Java2Win64 is the DLL that contains the native code to execute. Function functionMaryam() takes 1 param as int and returns an int. Easy to expand for any data type. public class JnaExampleMaryam {

    // ------------------------------------------
    // Java2Win.class
    // ------------------------------------------
    public interface Java2Win extends Library {
        Java2Win call = (Java2Win) Native.loadLibrary("Java2Win64", Java2Win.class);
        int functionMaryam(int i);
    }
    // ------------------------------------------
    
    // ------------------------------------------
    // Test
    // ------------------------------------------
    public static void main(final String args[]) throws Exception {
        final File file = new File("rootToDLL", "Java2Win64.dll");
        LibraryLoader.loadLibrary(file);
    
        int result = Java2Win.call.functionMaryam(42);
    }
    // ------------------------------------------
    
    0 讨论(0)
提交回复
热议问题