Jump to content
Excelsior Forums
Sign in to follow this  
rfrowd

Returning C pointer in xfunction

Recommended Posts

I am trying to use xfunction to interface from Java to a C DLL in MS Windows.

The function I am trying to call returns a pointer to a class.

In C:

typedef void *HPROB;

#define SOLVAPI extern "C"  __declspec(dllexport)

SOLVAPI HPROB  CoinCreateProblem(char *ProblemName);

I need to return this HPROB pointer to pass to the next call to the dll.

Can I just use a long variable type for this?

In Java:

          xFunction create =

              new xFunction("CoinMP", "long  CoinCreateProblem(CSTRING)");

Then to extract the return value:

          Argument arg1 = new Argument("CSS Problem", Argument.CSTRING);

          long hprob = (Long) create.invoke(arg1);

Then to pass it to the next function in the dll call:

          args[0] = new Argument(hprob);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×