473,386 Members | 1,835 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,386 software developers and data experts.

Writing binary data to registry

Hi!
Does anybody know how to write binary data to registry?
The purpose is to store an boxed object into registry and to
restore it.
Jul 21 '05 #1
4 4679
Dmitry <ka******@narod.ru> wrote:
Does anybody know how to write binary data to registry?
The purpose is to store an boxed object into registry and to
restore it.


I believe you can use RegistryKey.SetValue, passing in a byte array
containing the appropriate data.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Thanks, I did that!
IFormatter formatter = new BinaryFormatter();

// ?????? ??? ???????????? ? ??????

byte[] mas = new byte[1024];

Stream stream = new MemoryStream(mas);

formatter.Serialize(stream, obj);

long i = stream.Position;

stream.Close();

byte[] mas2 = new Byte[i];

// ????????? ???????? ?????? ?? mas ? mas2

for(int j = 0; j < i; j++)

{

mas2[j] = mas[j];

}

and there is a next problem.

how to calulate an accurate size of needed array (mas) ?

CurrentKey.SetValue(Name, mas2);

"Jon Skeet" <sk***@pobox.com> ???????/???????? ? ???????? ?????????:
news:MP************************@news.microsoft.com ...
Dmitry <ka******@narod.ru> wrote:
Does anybody know how to write binary data to registry?
The purpose is to store an boxed object into registry and to
restore it.


I believe you can use RegistryKey.SetValue, passing in a byte array
containing the appropriate data.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
Dmitry <ka******@narod.ru> wrote:

<snip>
and there is a next problem.

how to calulate an accurate size of needed array (mas) ?


You don't. Most of the code you posted isn't necessary. Instead, do:

Stream stream = new MemoryStream();
formatter.Serialize (stream, obj);
stream.Close();
byte[] data = stream.ToArray();

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
thanks again.
th? working code is:
MemoryStream stream = new MemoryStream();

formatter.Serialize(stream, obj);

stream.Close();

byte[] mas = stream.ToArray();

"Jon Skeet" <sk***@pobox.com> ???????/???????? ? ???????? ?????????:
news:MP************************@news.microsoft.com ...
Dmitry <ka******@narod.ru> wrote:

<snip>
and there is a next problem.

how to calulate an accurate size of needed array (mas) ?


You don't. Most of the code you posted isn't necessary. Instead, do:

Stream stream = new MemoryStream();
formatter.Serialize (stream, obj);
stream.Close();
byte[] data = stream.ToArray();

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5

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

Similar topics

8
by: Saradhi | last post by:
Can any one put me a piece of code to write binary data into Registry?
6
by: John Hoffman | last post by:
Reading registry: .... RegistryKey rksub = rkey.OpenSubKey(s); String valstr = rksub.GetValueNames(); foreach (String vs in valstr) { String vstr = rksub.GetValue(vs).ToString(); OR String...
6
by: Bry | last post by:
I'm having problems writing (and reading) boolean data to the registry. // Write a boolean value to the registry // I've not included the obvious bits of code in these samples bool myBool =...
4
by: Wolfgang Kaml | last post by:
I came accross the need to store binary data in the registry. The binary data to be saved is kept within a string in the code segment. If I write that string to a registry, not all of the data is...
5
by: Phil Kelly | last post by:
Hi I need to write the contents of a structure to a binary file - there is one string and 2 integers, but I can't seem to figure out how to write the data correctly. If I am simply writing...
1
by: Steve Bostedor | last post by:
I'm trying to use the RegistryKey to write a hex number into the registry as a binary type. I know see that in DotNet, the RegistryKey tries to interprate what registry type to create depending...
4
by: Dmitry | last post by:
Hi! Does anybody know how to write binary data to registry? The purpose is to store an boxed object into registry and to restore it.
4
by: RhavoX | last post by:
Hi. This may be a very stupid question but I'll leave you to judge it ;) I know there were lots of questions about this but none of the answers suits me. I'm wondering how to get the BINARY type...
2
by: Mike D. | last post by:
Hi All, Did an export from the registry (see below). This is what I need to have written to the registry programmatically from my VB.NET utility. As you can see it is multi-line and binary...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.