Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


DllImportAttribute.ExactSpelling Field

Definition

Controls whether the CharSet field causes the common language runtime to search an unmanaged DLL for entry-point names other than the one specified.

C#
public bool ExactSpelling;

Field Value

Examples

In some cases, Visual Basic developers use the DllImportAttribute, instead of using the Declare statement, to define a DLL function in managed code. Setting the ExactSpelling field is one of those cases.

C#
internal static class NativeMethods
{
    [DllImport("user32.dll", CharSet = CharSet.Unicode,
        ExactSpelling = true)]
    internal static extern int MessageBoxW(
        IntPtr hWnd, string lpText, string lpCption, uint uType);
}

Remarks

If false, the entry point name appended with the letter A is invoked when the DllImportAttribute.CharSet field is set to CharSet.Ansi, and the entry-point name appended with the letter W is invoked when the DllImportAttribute.CharSet field is set to the CharSet.Unicode. Typically, managed compilers set this field.

The following table shows the relationship between the CharSet and ExactSpelling fields, based on default values imposed by the programming language. You can override the default setting, but do so with caution.

Language ANSI Unicode Auto
Visual Basic ExactSpelling:=True ExactSpelling:=True ExactSpelling:=False
C# ExactSpelling=false ExactSpelling=false ExactSpelling=false
C++ ExactSpelling=false ExactSpelling=false ExactSpelling=false

Applies to

Termék Verziók
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0