Marshaling incorrect integer value
<p>I'm trying to develop a program to parse any string as given fixed character length. </p>

<p>Instead of writing my own parser class, I decided use marshaling. As below I defined a structure:</p>

<pre><code>[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MyStruct
{
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
    public string Name;              

    [MarshalAs(UnmanagedType.I4, SizeConst = 2)]
    public int Age;              

}
</code></pre>

<p>I call this struct like this;</p>

<pre><code>string message = "SampleName30";
IntPtr pBuf = Marshal.StringToBSTR(message);
MyStruct ms = (MyStruct)Marshal.PtrToStructure(pBuf, typeof(MyStruct));
</code></pre>

<p>If I check the value:</p>

<pre><code>ms.Name is SampleName // OK
</code></pre>

<p>But <code>ms.Age</code> value returns <code>3145779</code>. I expect <code>ms.Age = 30</code></p>

<p>What is the wrong?  How do I fix this problem?</p>
