I have a feeling I’m doing something wrong, but I’m not sure what.
Here is my code:
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();
}
}
}
When I load a file, the text at the above offset is 0x22 0x44 (“D in ASCII), yet the output to the text box is “68”…
I think I’m misunderstanding how bytes work, but I’m not entirely sure…
Any help is much appreciated!
In the text box you overwrite the value 34 (0x22) with the value 68 (0x44) on the second loop.
Your program works as it is programmed. A lucky escape for memory-mapped files.