2013-01-15 68 views
0

我有一種感覺,我做錯了什麼,但我不知道是什麼。爲什麼不能正確讀取這個內存映射文件?

這是我的代碼:

 long offset = 0x009694E3; 
     long length = 0x02; 
     byte[] bytes = new byte[length]; 

     // Create the memory-mapped file. 
     using (var mmf = 
      MemoryMappedFile.CreateFromFile(strFileName, FileMode.Open, "ISO")) 
     { 
      // Create a random access view, from the 256th megabyte (the offset) 
      // to the 768th megabyte (the offset plus length). 
      using (var accessor = mmf.CreateViewAccessor(offset, length)) 
      { 
       // Make changes to the view. 
       for (long i = 0; i < length; i++) 
       { 
        bytes[i] = accessor.ReadByte(i); 
        dialogEdit.Text = bytes[i].ToString(); 
       } 
      } 
     } 

當我加載文件,在上述偏移的文本是爲0x22 0x44進行(「在ASCII d),還輸出到文本框是‘68’。 ..

我想我誤解怎麼字節的工作,但我不能完全肯定...

任何幫助,非常感謝!

+0

所以... 0x22 0x44是兩個字節。哪一個字節是字節[0]?此外,字節上的ToString方法將返回一個數字,而不是ASCII字符。那裏需要進行編碼轉換。 – sdcoder

回答

1

在文本框中您覆蓋值34( 0x22) e值68(0x44)在第二個循環上。

您的程序按照程序運行。內存映射文件的幸運轉義。