.Net DLL only accepts ByteArray(1 to 32)

  • Thread starter Thread starter Benjamin Lukner
  • Start date Start date
B

Benjamin Lukner

Hi!

I'm using a .Net DLL that's referenced by my project.
The strange thing is that the DLL vendor uses byte arrays of 32 bytes
length having a lower bound of 1 to read and write data!

The only way I've found to create such an array is

Dim aData As System.Array = _
System.Array.CreateInstance( _
GetType(System.Byte), _
New Integer() {32}, _
New Integer() {1})

Does anyone know a neater way to do it?


Kind regards,

Benjamin Lukner
 
Stephany said:
Dim aData(31) As Byte

Funny ;-)

But the DLL does not accept aData(0 to 31). It only accepts aData(1 to
32) what is very annoying. .Net languages don't (officially) support
such arrays...

Benjamin
 
My point exactly. Therefore it must be aData(31) As Byte or the DLL is not
..NET.
 
Stephany said:
My point exactly. Therefore it must be aData(31) As Byte or the DLL is not
.NET.

The dll itself is .Net.
I assume that that dll is a wrapper around another dll that is not .Net.
The function accepts and returns a variable of type object.
The object I receive is of type System.Array.
To write I have to create such an array.

The question is not IF the dll is .Net but HOW to create an Array
beginning at "1" respectively if there is a better way than mine.

Kind regards,

Benjamin Lukner
 
A read of the documentation on System.Array.CreateInstance shows that the
particular overload you have shown is specifically designed to do what you
need to do.

Given that, apart from that overload, array subscripts are 0 based, I would
be suprised if there is another way let alone an easier way.

That overload, internally, after some parameter checking, executes:

Return Array.InternalCreateEx(type1, lengths, lowerBounds)

The other overloads that call Array.InternalCreateEx supply Nothing as the
3rd parameter and you can bet your bottom dollar that the result of that
give 0 based.

The upshot is, in my opinion, that you have it right.
 
By the way, that overload is NOT indicated as being supported in the Compact
Framework.
 
Back
Top