Using SWIG to handle char* argument that is modified by the method from Java to C++

I have a C++ method :

class classA
{
    public:
        bool methodA(const char* a, const int b, char* c);
}

This is used in the C++ application as follows:

int q = 5;
char returnOutput[512] = "";
char name[] = "someName";
classA objA = new classA();
bool x = objA->methodA(name, q, returnOutput);
if (x) 
{
    std::cout << "Return output from methodA is " <<returnOutput <<std::endl;
} 

When I use SWIG to create java wrappers for this method, it creates:

public Boolean methodA(String a, int b, String c) {
  return SampleJNI.classA_methodA(swigCptr, this, a, b, c);
}

Argument C is modified internally. Argument a isn't.

How can I handle the argument char* c in my interface file so that I can receive argument c similar to returnOutput in the java application?

The size of c will not always be 512 and I just used it as an example. Can that be determined dynamically?

I have these included in my interface file:

%javaconst(1);
%include "std_string.i" 
%include "std_list.i" 
%include "stl.i"
%include "std_auto_ptr.i" 
%include "std_common.i" 
%include "typemaps.i"
%include "enums.swg"
%include "std_map.i"
%include "std_auto_ptr.i"
%include "std_shared_ptr.i"
%include "swiginterface.i"
%include "swigmove.i"
%include "various.i"

Upvotes: 1

Views: 57

Answers (0)

Related Questions