Writing binary data to registry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dmitry

    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.


  • Jon Skeet

    #2
    Re: Writing binary data to registry

    Dmitry <karneyev@narod .ru> wrote:[color=blue]
    > Does anybody know how to write binary data to registry?
    > The purpose is to store an boxed object into registry and to
    > restore it.[/color]

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

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Dmitry

      #3
      Re: Writing binary data to registry

      Thanks, I did that!
      IFormatter formatter = new BinaryFormatter ();

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

      byte[] mas = new byte[1024];

      Stream stream = new MemoryStream(ma s);

      formatter.Seria lize(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.SetV alue(Name, mas2);

      "Jon Skeet" <skeet@pobox.co m> ???????/???????? ? ???????? ?????????:
      news:MPG.19c929 0229f44d9198968 7@news.microsof t.com...[color=blue]
      > Dmitry <karneyev@narod .ru> wrote:[color=green]
      > > Does anybody know how to write binary data to registry?
      > > The purpose is to store an boxed object into registry and to
      > > restore it.[/color]
      >
      > I believe you can use RegistryKey.Set Value, passing in a byte array
      > containing the appropriate data.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Jon Skeet

        #4
        Re: Writing binary data to registry

        Dmitry <karneyev@narod .ru> wrote:

        <snip>
        [color=blue]
        > and there is a next problem.
        >
        > how to calulate an accurate size of needed array (mas) ?[/color]

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

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

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Dmitry

          #5
          Re: Writing binary data to registry

          thanks again.
          th? working code is:
          MemoryStream stream = new MemoryStream();

          formatter.Seria lize(stream, obj);

          stream.Close();

          byte[] mas = stream.ToArray( );

          "Jon Skeet" <skeet@pobox.co m> ???????/???????? ? ???????? ?????????:
          news:MPG.19c939 c946755a3b98968 8@news.microsof t.com...[color=blue]
          > Dmitry <karneyev@narod .ru> wrote:
          >
          > <snip>
          >[color=green]
          > > and there is a next problem.
          > >
          > > how to calulate an accurate size of needed array (mas) ?[/color]
          >
          > You don't. Most of the code you posted isn't necessary. Instead, do:
          >
          > Stream stream = new MemoryStream();
          > formatter.Seria lize (stream, obj);
          > stream.Close();
          > byte[] data = stream.ToArray( );
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          Working...