mnn
mnn

Reputation:

How to import const int * const buffer[] into C#?

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.

Upvotes: 0

Views: 457

Answers (4)

mnn
mnn

Reputation:

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!

Upvotes: 0

Stephen Martin
Stephen Martin

Reputation: 9645

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;

Upvotes: 1

dreamlax
dreamlax

Reputation: 95355

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

Upvotes: 1

paxdiablo
paxdiablo

Reputation: 882116

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.

Upvotes: 3

Related Questions