DllImportAttribute.ExactSpelling Поле
Определение
Контролирует запуск поиска имен точек входа помимо заданной точки в неуправляемой динамической библиотеке (DLL), выполняемого средой CLR, полем CharSet.Controls whether the CharSet field causes the common language runtime to search an unmanaged DLL for entry-point names other than the one specified.
public: bool ExactSpelling;
public bool ExactSpelling;
val mutable ExactSpelling : bool
Public ExactSpelling As Boolean
Значение поля
Примеры
В некоторых случаях Visual Basic разработчики используют DllImportAttribute вместо Declare
инструкции, чтобы определить функцию DLL в управляемом коде.In some cases, Visual Basic developers use the DllImportAttribute, instead of using the Declare
statement, to define a DLL function in managed code. Установка ExactSpelling поля является одним из этих вариантов.Setting the ExactSpelling field is one of those cases.
[DllImport("user32.dll", CharSet = CharSet::Ansi, ExactSpelling = true)]
int MessageBoxA(IntPtr hWnd, String^ Text,
String^ Caption, unsigned int Type);
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);
}
Friend Class NativeMethods
<DllImport("user32.dll", ExactSpelling:=False)>
Friend Shared Function MessageBox(hWnd As IntPtr, lpText As String,
lpCaption As String, uType As UInteger) As Integer
End Function
End Class
Комментарии
Если значение равно false
, то имя точки входа, к которой добавляется буква A, вызывается DllImportAttribute.CharSet , когда поле установлено в CharSet.Ansi
, а имя точки входа, добавленное с буквой W, вызывается, если DllImportAttribute.CharSet для поля задано значение CharSet.Unicode
.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.
В следующей таблице показана связь между CharSet полями и ExactSpelling на основе значений по умолчанию, установленных языком программирования.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 | ANSIANSI | ЮникодUnicode | Auto (Автоматически)Auto |
---|---|---|---|
Visual BasicVisual Basic | ExactSpelling: = trueExactSpelling:=True | ExactSpelling: = trueExactSpelling:=True | ExactSpelling: = falseExactSpelling:=False |
C#C# | ExactSpelling = falseExactSpelling=false | ExactSpelling = falseExactSpelling=false | ExactSpelling = falseExactSpelling=false |
C++C++ | ExactSpelling = falseExactSpelling=false | ExactSpelling = falseExactSpelling=false | ExactSpelling = falseExactSpelling=false |