12 Replies Latest reply: May 13, 2011 2:21 PM by jschellSomeoneStoleMyAlias RSS

    Accessing a native method whose return type is an object of a Class

    860480
      Hi Everyone,

      Here goes my doubt in accessing of NATIVE FUNCTIONS in my JAVA CODE (using JNA)

      if the method inside my DLL is declared as follows:
      extern "C" __declspec(dllexport) int myMethod();

      that means i just need to declare a native equivalent of 'myMethod' to use it in my java code like:

      public native int myMethod();

      Now i can call the function as follows: int var = myMethod();

      //********************Now the MAIN part***********************\\

      Inside the DLL, I also have a class along with the method which goes as follows:

      class MyClass
      {
      public:
      int var;
      };

      extern "C" __declspec(dllexport) MyClass __cdecl myMethod()
      {
      MyClass obj;
      obj.var = 45;
      return obj;
      }
      ///////////////////////////DLL code ends\\\\\\\\\\\\\\\\\\\\\\\\

      I hope you all noticed that now my return type is an object of a class rather than a normal int.

      So, now the bigger question is, how I am going to use this native function (myMethod) inside my JAVA code? Previously the return type was just an integer, so it was easy. But now what or rather how?

      It's very urgent. So, i would really be grateful if someone can provide me with any kind of solutions or helpful links?

      Thanks in advance,

      With regards,
      Satya Prakash.