0

I have an vb.net executable that calls a c++/clr dll (that in turn calls a native c++ dll). I need to pass arrays between all three. In vb.net I use the following:

Dim arrsize = 10
Dim array(arrsize,arrsize) as Double

then I pass this to c++/clr code

result = vbcalltocppcode(array)

and in c++/clr code (inside a public ref classthat i create an instance of in vb.net)

bool vbcalltocppcode(array<double,2>^ clrarray)

If I try to extract the length of this using

size_t cpparrsize = clrarray->GetLength(1);

cpparrsize = 11. Why is this? Is there any overhead that I don't see or what?

(the reason for this is that when I try to populate this in the native c++ code with arrays of rank 2 and 3, assuming in native c++ that the array is one dimensional I loose some values, i.e. some values are put in clrarray[*,11] which I do not want.)

Of course I could solve this just skipping what I believe to be the 11th index but since I am not sure this seems a bit hazardous.

1 Answer 1

1

That's just how Basic works, you actually allocated an 11x11 array. Best way to think about it: you specify the last valid index in the array.

This quirkiness was induced by having to stay compatible with previous Basic versions for the past 40 years. Way back when, arrays started indexing at 1 instead of 0. Still around to some degree, COM object models like Office can start their arrays at 1.

Fix:

Dim arrsize = 9
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot @Hans Passant!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.