Structure to MemoryStream

How to write in Memorystream, Structure. Or mybe its inposible :) i doubt that.

Structor its self is stored in memory so in theory it is posible to write it in Memorystream.

in delphi its easy m'kay =)


 stream.write(buf, sizeof(buf));

thats how it is done in Delphi.

In APS.NET i tried more than i want to continue it.

so i have somethin like this now


Imports System
Imports System.Net
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Threading
Imports System.Net.Sockets
Imports System.Text
Imports System.Globalization

Public Structure sHeder
    Dim Versija As Integer
End Structure

Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim st As New MemoryStream
        Dim hed As sHeder

        hed.Versija = 1

        st.Write(hed, 0, 11) ''Ye ye ye i know it doesn't work like this, here i need some ideas.
        st.Seek(0, SeekOrigin.Begin)

    End Sub
End Class

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure what your end goal is...this might spark some ideas:

Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Form1

    <Serializable()> Public Structure sHeder

        Public Versija As Integer

        Public Function Clone() As sHeder
            Dim bf As BinaryFormatter = New BinaryFormatter
            Dim ms As MemoryStream = New MemoryStream
            bf.Serialize(ms, Me)
            ms.Seek(0, SeekOrigin.Begin)
            Dim sh As sHeder = CType(bf.Deserialize(ms), sHeder)
            Return sh
        End Function

    End Structure

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hedA, hedB As sHeder
        hedA.Versija = 1
        hedb.Versija = 2
        Debug.WriteLine("Two different hSeder structures:")
        Debug.WriteLine("hedA.Versija = " & hedA.Versija)
        Debug.WriteLine("hedB.Versija = " & hedb.Versija)

        Debug.WriteLine("After cloning:")
        hedb = hedA.Clone
        Debug.WriteLine("hedA.Versija = " & hedA.Versija)
        Debug.WriteLine("hedB.Versija = " & hedb.Versija)
    End Sub

End Class

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KristaoAuthor Commented:
Yep this is what i seek.

Now why i need it. I thik you noticed this "Imports System.Net.Sockets" =)

I cut out litle part of tcpclient functions. So it wouldn't do mess in exsample. In Delphi comunication, i transfer all data in one big stream. Stream wich includes heders, wich countains information about stream, wich comes in. So becouse i need to connect to server wich is writen in Delphi, i need to remake comunication in ASP.NET. I say nothing hard, but with my litle experiance in ASP.NET don't know all posibilitys in ASP.NET. For exsample to this day i didn't realy know is it posible to make tcp/ip client. But i found its prety easy, love

Don't realy know will this exsample what you gave me will work like i wan't, but you gave me the idea, and the way i need to look. thx =)

If you are interested about results i can put here an exsample of my code, after it will be ready :).

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.