0

I'm good in c# and i need help in JAVA.

I have a c++ function that outs 4 variables

int Func1(int inParam1, unsigned char* inParam2, int *outParam1, int *outParam2, int *outParam3, unsigned char** outParam4);

I can call this function from C# using PInvoke like this

[DllImport("CLSFPCaptureDLL.dll"]
       int Func1(int inParam1, byte[] inParam2, out IntPtr outParam1, out IntPtr outParam2, out IntPtr outParam3, out IntPtr outParam4);

But now i need to call the c++ function in java. I have write a JNI with a java class that needs to out these 4 variables. How can i do it in JAVA ?

Narayan
  • 1,189
  • 6
  • 15
  • 33

1 Answers1

2

You need a bridge in c++.

Be sure to read about JNI so you can better follow my sample.

In C++, create a class and compile it to a dll so that it finds and links to CLSFPCaptureDLL.dll. Read about JNI function, that will help you build the output.

Java:

Test1.java:

package test;

public class Test1 {

    static {
        System.loadLibrary("YourLibrary");
    }

    public static byte[] myJniFunc();
}

and C++:

Test.cpp:

extern "C"
{
    JNIEXPORT jobject JNICALL Java_test_Test1_myJniFunc(JNIEnv *env, jclass cls)
    {
        // Make all the data you need, and pass it back as a jbyteArray
    }
}
Chen Harel
  • 9,684
  • 5
  • 44
  • 58
  • Ya i tried JNI. This code can out (return) only one byte[]. but i need to return a btye array 3 integers. how can i pass it – Narayan Feb 09 '13 at 07:00
  • I made the 4 out variables as properties and set it from the JNI. then i get the values from Java application. If someone needs detail answer i'll post my answer code. – Narayan Feb 09 '13 at 10:59
  • That's great. I actually meant that you serialize the 4 parameters yourself and deserialize in java but whatever works .. – Chen Harel Feb 09 '13 at 14:49