471,344 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

how to convert byte[] to object[]

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
Jun 27 '08 #1
6 3929
On Thu, 24 Apr 2008 08:06:18 -0700, <EF@nospam.nospamwrote:
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
Jun 27 '08 #2
EF@nospam.nospam wrote:
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

Jun 27 '08 #3
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 [C++ MVP]" wrote:
EF@nospam.nospam wrote:
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


Jun 27 '08 #4
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" wrote:
On Thu, 24 Apr 2008 08:06:18 -0700, <EF@nospam.nospamwrote:
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
Jun 27 '08 #5
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:
ms****@microsoft.com.

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

Jun 27 '08 #6

"Alex" <EF@nospam.nospamwrote in message
news:12**********************************@microsof t.com...
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 [C++ MVP]" wrote:
>EF@nospam.nospam wrote:
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


Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Nathan | last post: by
1 post views Thread by Lamberti Fabrizio | last post: by
9 posts views Thread by Charles Law | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.