473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

convert object to byte []

I need to get byte values from an object into a byte[] in order to write the
bytes to file.

An object (vSound) is passed to a function.
From the Autos window I can see that the Value of vSound is {System.Array}
and the Type is {System.Object}.
vSound has no properties or methods that allow you to get access to the byte
values.
When I type
?vSound
in the command window, I get:
{System.Array}
[1]: 36
[2]: 0
[3]: 8
[4]: 0
[5]: 220
....
[800]: 5
I can't figure out how to legally cast the object to a byte array.
I tried
byte[] mybyte;
mybyte = (Byte[]) vSound;
Any ideas? Thanks.
Nov 15 '05 #1
1 25622
Use BinaryFormatter class in (check MSDN)
using System.Runtime.Serialization.Formatters.Binary;

it returns Serialized object into the Stream;

So you can use this Code:

Stream
myStream=File.Open("myfile.bin",FileMode.Create,Fi leAccess.ReadWrite);

BinaryFormatter formatter=new BinarryFomatter();

formatter.Serialize(myStream, someObject);

And your object will be automatic put into file as Stream. And later if you
want to deserialize, justa call method for deserialize
formatter.Deserialize(myStream)

"steve" <cs********@yahoo.com> wrote in message
news:#E**************@TK2MSFTNGP12.phx.gbl...
I need to get byte values from an object into a byte[] in order to write the bytes to file.

An object (vSound) is passed to a function.
From the Autos window I can see that the Value of vSound is {System.Array}
and the Type is {System.Object}.
vSound has no properties or methods that allow you to get access to the byte values.
When I type
?vSound
in the command window, I get:
{System.Array}
[1]: 36
[2]: 0
[3]: 8
[4]: 0
[5]: 220
...
[800]: 5
I can't figure out how to legally cast the object to a byte array.
I tried
byte[] mybyte;
mybyte = (Byte[]) vSound;
Any ideas? Thanks.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nathan | last post by:
Is there a way to convert a string to a CipherMessage? I am calling a function that decrypts a CipherMessage and returns the value. The only problem is when I want to use an encrypted value stored...
1
by: Lamberti Fabrizio | last post by:
Hi all. I've got an ActiveX Object that gives me OleColor codes for its graphical components. I need to convert these OleColor codes into RGB codes using JScript or VBScript, becuase I have...
6
by: Gator | last post by:
Hi All, Basically my situation is this, I have a server implemented in C++, unmanaged code, using proprietery protocol over TCP/IP to communicate with the cilent(c++ also). Now, I am implementing...
4
by: Serge Klokov | last post by:
Hello! I have a Oracle table with a BLOB field. Each field is actually a simple text file of several lines. How to get this BLOB fields in readable format? I tryied something like...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
9
by: Charles Law | last post by:
Suppose I have a structure Private Structure MyStruct Dim el1 As Byte Dim el2 As Int16 Dim el3 As Byte End Structure I want to convert this into a byte array where
8
by: Serge BRIC | last post by:
My application, written in .NET VB, tries to get a communication port handle from a TAPI object with this code: Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem") The...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.