I\'ve got a project using memory mapped files to let two apps share data with each other. The producer app is written in C#, the consumer app talks plain old C. Both use VS2
While the MSDN Documentation on BinaryWriter.Write states it “first writes the length of the string as a UTF-7 encoded unsigned integer”, it is wrong. First of all, UTF-7 is a string encoding, you cannot encode integers using UTF-7. What the documentation means (and the code does) is that it writes the length using variable-length 7-bit encoding, sometimes known as LEB128. In your specific case, the data bytes 80 02
mean the following:
1000 0000 0000 0010
Nbbb bbbb Eaaa aaaa
N
set to one means this is not the final byteE
set to zero means this is the final byteaaaaaaa
and bbbbbbb
are the real data; the result is therefore:
00000100000000
aaaaaaabbbbbbb
I.e. 100000000
in binary, which is 256 in decimal.
Despite what the Microsoft documentation says,
The Wiki page I linked gives you decoding code, but I would consider using my own scheme. You could convert the string to UTF8 manually using Encoding.GetBytes() and write that to the MMF, prefixing it with a normal unsigned short. That way you have complete control over everything.