Jump to content
Excelsior Forums
jpusateri

void** pointers

Recommended Posts

I have a dll with a call that requires a void ** pointer.

It is expected that the called program will allocate some struct and hang it on the end of that pointer.  I create a pointer using:

Pointer.create("int**") since I can't use a void**.

When I make the call, a Dr. Watson error occurs.

I don't know the struct and it is not available to me.

1) Is it legal for the native program to allocate space that I can reference?  No space boundary problems?

2) Do I need to allocate the space first?  In C, this is legal, even common, to do this.  But in Java....?

Any help?

TIA.

Share this post


Link to post
Share on other sites

Hi,

you can use the following way to pass the 'pointer to something' to the Java program:

//in b.c
int buffer[100] = {1, 2, 3};

__declspec(dllexport) void __stdcall foo(int** a) {
   *a = buffer;
}

//in b.java
public static void main(String[] args) throws xFunctionException {
       Pointer arg = Pointer.create("int*");

       xFunction foo = new xFunction("b", "void _foo@4(int*)");
       foo.invoke(arg);
//now arg points to the address passed, but supposes that it is not address, but simple int, so we cast the pointer to 'pointer to pointer to what we need', and then deref

       Pointer a = (Pointer)arg.cast("int**").deref();

//then we may use the retrieved value
       int[] arr = (int[])a.createArray(2);
       System.out.println("" + arr[0] + ", " + arr[1]);
}

I hope this would help.

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

×