views:

261

answers:

4

This is tricky for me.

const int * const buffer[]

Currently, I have it translated as follows:

byte[] buffer

Problem is that I'm getting AccessViolation exceptions, when DLL is calling function with that is using above parameter.

Thanks for help.

+2  A: 

With two const's surely that should be indication enough that you're not allowed to change it :-). But, seriously, one of those states that the pointer shouldn't change, the other states that the data pointed to by the pointer shouldn't change.

That's why you're getting the access violation.

What you'll need to do is to copy, not just cast, the data to another buffer which is somewhat less const. Hint: Buffer.BlockCopy is the way to go.

paxdiablo
+1  A: 

Isn't sizeof(int) > sizeof(byte)? If so, then you will get issues, surely.

dreamlax
They may make the byte array four times bigger. That would be my guess.
paxdiablo
+1  A: 

The const modifiers do not affect the PInvoke signature, though they may affect how you deal with the data. Since the buffer parameter is an array of pointers to integers the correct translation would be:

IntPtr[] buffer;
Stephen Martin
A: 

Edit: it works now, no AccessViolation exceptions, but I don't know how to retrieve data properly from array like that.

Example file is using this type of access:

buffer[0][i]
buffer[1][i]

but I have only 1 pointer in buffer[]. That pointer is pointer to an 2 dimensional array? How to marshal it then to .NET? Thanks!

Please edit your original question with the updated information. This isn't an answer. :)
Robert P