Click here to Skip to main content
15,895,256 members
Home / Discussions / C#
   

C#

 
AnswerRe: Active Directory - Null Reference Exception Pin
Anthony Mushrow1-May-08 0:45
professionalAnthony Mushrow1-May-08 0:45 
Questionfunction conference Pin
asma_pfe30-Apr-08 22:24
asma_pfe30-Apr-08 22:24 
AnswerRe: function conference Pin
Christian Graus30-Apr-08 23:05
protectorChristian Graus30-Apr-08 23:05 
GeneralRe: function conference Pin
asma_pfe1-May-08 0:09
asma_pfe1-May-08 0:09 
GeneralRe: function conference Pin
Christian Graus1-May-08 2:58
protectorChristian Graus1-May-08 2:58 
GeneralRe: function conference Pin
Bert delaVega1-May-08 4:12
Bert delaVega1-May-08 4:12 
GeneralRe: function conference Pin
asma_pfe2-May-08 3:21
asma_pfe2-May-08 3:21 
QuestionI am not able to see large icon in list view Pin
Naveed72730-Apr-08 21:48
Naveed72730-Apr-08 21:48 
AnswerRe: I am not able to see large icon in list view Pin
Christian Graus30-Apr-08 23:07
protectorChristian Graus30-Apr-08 23:07 
Questiontriggers with a stored procedure Pin
Member 400849230-Apr-08 21:37
Member 400849230-Apr-08 21:37 
AnswerRe: triggers with a stored procedure Pin
Christian Graus30-Apr-08 23:07
protectorChristian Graus30-Apr-08 23:07 
Questionrun asp.net appn on iis Pin
Member 443208630-Apr-08 21:02
Member 443208630-Apr-08 21:02 
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 

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.