Jump to content
Excelsior Forums
loggo

How do I use unsigned char*

Recommended Posts

Hi,

How do I pass an array of bytes into a dll using xfunction? The underlying dll expects an unsigned char*.

I'd like to make the following call:

             xFunction f=new xFunction("s87d.dll", "int CreateSignature(unsigned char*, int, short*, int, int)");

             byte[] buff = new byte[48000];

             Pointer arg1 = (Pointer) Argument.create("unsigned char*", buff);

As xfunction doesn't support unsigned char* is there some other way of doing this?

Share this post


Link to post
Share on other sites

From the point of view of underlying dll, there is no difference what type was used in xFunction's signature. The only matter is the binary layout of the arguments.

So, specifying simple "char*" is correct.

Share this post


Link to post
Share on other sites

That's fine but if I use char* I need to use a char[] and that's not what I want.

The function wont take a byte[] for a char* pointer and the underlying dll requires a preallocated array of bytes to write to.

I know I'm missing the point here so can you show me how the code should look?

Share this post


Link to post
Share on other sites

Suppose underlying dll fills buffer with bytes {0xAB, 0xCD, ...}. The code in xFunction may looks like

xFunction f=new xFunction("s87d.dll", "int CreateSignature(char*, int, short*, int, int)"); 
   Pointer arg1 = (Pointer) Argument.create("char*", new char[48000]);
   ....
   f.invoke(arg1, ...);
   char[] buff = (char[])arg1.createArray(48000);
   byte b1 = (byte)buff[0]; //=0xAB
   byte b2 = (byte)buff[1]; //=0xCD
...

   

Share this post


Link to post
Share on other sites

Many thanks. I'd already tried something similar but I'd made a simple error which threw me. It all works now and I've just tried it for another project I'm looking at and it only took 30 mins to get it all working!

xfunction should be in the core language!

As a convenience could a future version include the option to specify information as bytes?

Share this post


Link to post
Share on other sites

The only reason why the 'byte' type was not implemented is trying to avoid confusion with 2 Java types (byte, char) corresponding to one C type. However, we will take into account your wishes and maybe will implement it in future.

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

×