+The way `char` values, `string` objects, and `System.Text.StringBuilder` objects are marshaled depends on the value of the `CharSet` field on either the P/Invoke or structure. You can set the `CharSet` of a P/Invoke by setting the <xref:System.Runtime.InteropServices.DllImportAttribute.CharSet?displayProperty=nameWithType> field when declaring your P/Invoke. To set the `CharSet` for a type, set the <xref:System.Runtime.InteropServices.StructLayoutAttribute.CharSet?displayProperty=nameWithType> field on your class or struct declaration. When these attribute fields are not set, it is up to the language compiler to determine which `CharSet` to use. C#, Visual Basic, and F# use the <xref:System.Runtime.InteropServices.CharSet.None> charset by default, which has the same behavior as the <xref:System.Runtime.InteropServices.CharSet.Ansi> charset.
0 commit comments