Click here to Skip to main content
15,867,308 members
Home / Discussions / C#
   

C#

 
AnswerRe: run asp.net appn on iis Pin
som.nitk30-Apr-08 21:35
som.nitk30-Apr-08 21:35 
AnswerRe: run asp.net appn on iis Pin
Christian Graus30-Apr-08 23:09
protectorChristian Graus30-Apr-08 23:09 
QuestionHow to get all files name from Property.Resourece Pin
Guru Call30-Apr-08 20:32
Guru Call30-Apr-08 20:32 
AnswerRe: How to get all files name from Property.Resourece Pin
Gopal.S1-May-08 1:34
Gopal.S1-May-08 1:34 
QuestionDisplaying lines of code as a program runs Pin
MarkB77730-Apr-08 20:13
MarkB77730-Apr-08 20:13 
AnswerRe: Displaying lines of code as a program runs Pin
Christian Graus30-Apr-08 20:15
protectorChristian Graus30-Apr-08 20:15 
GeneralRe: Displaying lines of code as a program runs Pin
Roger Alsing30-Apr-08 21:48
Roger Alsing30-Apr-08 21:48 
QuestionFile Structure Serialization Pin
Ian Uy30-Apr-08 20:05
Ian Uy30-Apr-08 20:05 
Good Day,

I am working in an encryption utility as a school project. I'm all done with the byte manipulations and stuffs and just need to write the data as a file. I have already conceptualized the File Structure and is coded as:

[StructLayout(LayoutKind.Sequential)]<br />
struct LockFile<br />
{<br />
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]<br />
    public string MagicNumber;<br />
    public Hashtable IncrementalMappingArray;<br />
}


I need to Serialize that structure using this function I found somewhere:

private static byte[] RawSerialize(object anything)<br />
        {<br />
            int rawsize = Marshal.SizeOf(anything);<br />
            IntPtr buffer = Marshal.AllocHGlobal(rawsize);<br />
            Marshal.StructureToPtr(anything, buffer, false);<br />
            byte[] rawdatas = new byte[rawsize];<br />
            Marshal.Copy(buffer, rawdatas, 0, rawsize);<br />
            Marshal.FreeHGlobal(buffer);<br />
            return rawdatas;<br />
        }


Then I write it as file:
            LockFile theLockFile = new LockFile();<br />
            theLockFile.MagicNumber = "myLock";<br />
            theLockFile.IncrementalMappingArray = IMA;<br />
            <br />
            byte[] LockFileStream = RawSerialize(theLockFile);<br />
<br />
            MessageBox.Show(LockFileStream.Length.ToString());<br />
<br />
<br />
            string Filename = Path.GetFileNameWithoutExtension(txtPath.Text);<br />
<br />
            string LockFilePath = Path.GetDirectoryName(txtPath.Text);<br />
<br />
            File.WriteAllBytes(LockFilePath + "\\" + Filename + ".flk", LockFileStream);


But it always write the same value with 4 bytes in it. But the IMA (Hashtables) contains a lot of key-value pair. (Like 5mb).

Do I need to convert the hashtable to a byte[] first?

Thanks!

It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

AnswerRe: File Structure Serialization Pin
carbon_golem1-May-08 2:59
carbon_golem1-May-08 2:59 
GeneralRe: File Structure Serialization Pin
Ian Uy1-May-08 3:05
Ian Uy1-May-08 3:05 
GeneralRe: File Structure Serialization Pin
carbon_golem1-May-08 3:41
carbon_golem1-May-08 3:41 
GeneralRe: File Structure Serialization Pin
Ian Uy1-May-08 3:49
Ian Uy1-May-08 3:49 
GeneralRe: File Structure Serialization Pin
carbon_golem1-May-08 3:57
carbon_golem1-May-08 3:57 
QuestionPlease Help !Query executing in oracle but not executing through code Pin
ravindradonkada30-Apr-08 19:46
ravindradonkada30-Apr-08 19:46 
AnswerRe: Please Help !Query executing in oracle but not executing through code Pin
Christian Graus30-Apr-08 20:18
protectorChristian Graus30-Apr-08 20:18 
AnswerRe: Please Help !Query executing in oracle but not executing through code [modified] Pin
Mircea Puiu1-May-08 4:46
Mircea Puiu1-May-08 4:46 
QuestionDetect Shift when Menu Opens Pin
Chris_McGrath30-Apr-08 19:28
Chris_McGrath30-Apr-08 19:28 
AnswerRe: Detect Shift when Menu Opens Pin
Chris_McGrath30-Apr-08 19:45
Chris_McGrath30-Apr-08 19:45 
QuestionHOW TO CREATE AN INSTANCE OF INTERNET EXPLORER AND HOW TO USE IT? Pin
syamooo30-Apr-08 18:55
syamooo30-Apr-08 18:55 
AnswerRe: HOW TO CREATE AN INSTANCE OF INTERNET EXPLORER AND HOW TO USE IT? Pin
Christian Graus30-Apr-08 19:18
protectorChristian Graus30-Apr-08 19:18 
GeneralRe: HOW TO CREATE AN INSTANCE OF INTERNET EXPLORER AND HOW TO USE IT? Pin
syamooo30-Apr-08 19:38
syamooo30-Apr-08 19:38 
GeneralRe: HOW TO CREATE AN INSTANCE OF INTERNET EXPLORER AND HOW TO USE IT? Pin
Christian Graus30-Apr-08 19:53
protectorChristian Graus30-Apr-08 19:53 
GeneralRe: HOW TO CREATE AN INSTANCE OF INTERNET EXPLORER AND HOW TO USE IT? Pin
Zoltan Balazs30-Apr-08 20:00
Zoltan Balazs30-Apr-08 20:00 
GeneralRe: HOW TO CREATE AN INSTANCE OF INTERNET EXPLORER AND HOW TO USE IT? Pin
Christian Graus30-Apr-08 20:13
protectorChristian Graus30-Apr-08 20:13 
GeneralRe: HOW TO CREATE AN INSTANCE OF INTERNET EXPLORER AND HOW TO USE IT? Pin
Zoltan Balazs30-Apr-08 20:30
Zoltan Balazs30-Apr-08 20:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.