In java i am using JNA to load VC++ dll file and calling functions within it,in one function i need to send 6 parameters,In VC++ function definition i am getting correct values for first 3 parameters but last 3 are having value ‘0’,
2nd parameter is byte array,when i send 1024 bytes, i am getting 5th bool parameter as false but when i pass 10 bytes it is taken as true
my function prototype :int deviceupload(Pointer p, _byte[] data_, long startaddress, long datalength,_Boolean rt_,Pointer xyz);
So will mapping changes depending upon the size of parameters?
or JNA stack is so small that it cant hold 6 paramters?but according to JNA documentation MAX_NARGS of Function class value is 256 so i think 6 number of parameters is not an issue,
even though 3rd and 4th parameters have same data type,in VC++ function definition startaddress is correctly received but datalength received value is 0
so any idea why it is behaving so weird ?
Arguments are placed in memory “slots” on the stack. A small argument might take one slot, or share a slot with another argument, while a large argument might take two slots. You can see how if you mistake a small argument for a large one, it will shift all the subsequent arguments into incorrect positions.
void my_func(int32 p1, int64 p2)
Now if you mistakenly use a 64-bit value for P1, you get this instead:
The callee (the function you called) has no idea that this shift has taken place, and therefore attempts to read the arguments from their expected positions. For small arguments it might get a piece of a larger one, and for larger arguments it might get pieces of two or more other arguments.
What the callee actually sees is this:
You can see that the value read for P1 is actually only half of the larger value, while the value read for P2 comprises the other half of P1 and half of the value passed in as P2.
(This explanation is somewhat simplified, but generally indicates how the stack works)