StructLayoutAttribute.CharSet Field


指示在默认情况下是否应将类中的字符串数据字段作为 LPWSTRLPSTR 进行封送处理。Indicates whether string data fields within the class should be marshaled as LPWSTR or LPSTR by default.

public: System::Runtime::InteropServices::CharSet CharSet;
public System.Runtime.InteropServices.CharSet CharSet;
val mutable CharSet : System.Runtime.InteropServices.CharSet
Public CharSet As CharSet 

Field Value



如果 CharSet 字段设置为 CharSet.Unicode,则在将所有字符串参数传递到非托管实现之前,会将其转换为 Unicode 字符(LPWSTR)。If the CharSet field is set to CharSet.Unicode, all string arguments are converted to Unicode characters (LPWSTR) before they are passed to the unmanaged implementation. 如果字段设置为 CharSet.Ansi,则字符串将转换为 ANSI 字符串(LPSTR)。If the field is set to CharSet.Ansi, the strings are converted to ANSI strings (LPSTR). 如果 CharSet 字段设置为 CharSet.Auto,则转换与平台相关(在 Windows 98 和 Windows Me 上为 ANSI,在更高版本上为 Unicode)。If the CharSet field is set to CharSet.Auto, the conversion is platform-dependent (ANSI on Windows 98 and Windows Me, and Unicode on later versions).

Applies to

See also