how to convert byte[] to object[]

G

Guest

Hi,

How do I convert a byte[] to an object[]?

I am trying to use IADs PutEx and the last parameter required a variant
array.

Thanks,
Alex
 
B

Ben Voigt [C++ MVP]

Hi,

How do I convert a byte[] to an object[]?

I am trying to use IADs PutEx and the last parameter required a
variant array.

I suspect what you need is:

byte[] barray;
PutEx(..., new object[] { barray });
 
A

Alex

Hi Ben,

Thanks for the suggestion.

What I did to make it work is:

object[] objArr = new object[1];
objArr[0] = barray;
PutEx(....,objArr);

As I am just learning C# so I am not so familar with your syntax. Is it
doing the same?

Thanks,
Alex


Ben Voigt said:
Hi,

How do I convert a byte[] to an object[]?

I am trying to use IADs PutEx and the last parameter required a
variant array.

I suspect what you need is:

byte[] barray;
PutEx(..., new object[] { barray });
Thanks,
Alex
 
A

Alex

Hi Peter,

I did manage to convert byte[] to object[] using Arrays.Copy but it does not
solve me problem. Actually PutEx is expecting an object array containing
byte array. Doing that so my problem.

Thanks,
Alex

Peter Duniho said:
How do I convert a byte[] to an object[]?

Copy each element to an object[]. I take as granted that you really have
to do this, 'cause it's not going to be efficient. :)

Pete
 
J

Jeffrey Tan[MSFT]

Hi Alex,

Thanks for your feedback.

Actually your code works the same way as what Ben provided. "new object[] {
barray }" means creating an object array with length determined by the
number of elements in {}. Since there is only one element "barray" in the
{}, the object array will have length "one". Also, in this one element
object array, the only element is a reference to the byte array. This is
the same logic as your code does

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Ben Voigt [C++ MVP]

Alex said:
Hi Ben,

Thanks for the suggestion.

What I did to make it work is:

object[] objArr = new object[1];
objArr[0] = barray;
PutEx(....,objArr);

As I am just learning C# so I am not so familar with your syntax. Is it
doing the same?

Yes, the compiler will expand

new T[] { t1, t2, ... tn }

into

T[] temp = new T[n];
temp[0] = t1;
temp[1] = t2;
temp[n-1] = tn;

and use temp in the original function call

Thanks,
Alex


Ben Voigt said:
Hi,

How do I convert a byte[] to an object[]?

I am trying to use IADs PutEx and the last parameter required a
variant array.

I suspect what you need is:

byte[] barray;
PutEx(..., new object[] { barray });
Thanks,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top