Export (0) Print
Expand All

DllImportAttribute.ExactSpelling Field

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

[Visual Basic]
Public ExactSpelling As Boolean
[C#]
public bool ExactSpelling;
[C++]
public: bool ExactSpelling;
[JScript]
public var ExactSpelling : Boolean;

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

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
Imports System.Runtime.InteropServices
Public Class Win32   
    <DllImport ("user32.dll", ExactSpelling := False)> _
    Public Shared Function MessageBox (ByVal hWnd As Integer, _
        ByVal txt As String, ByVal caption As String, _
        ByVal Typ As Integer) As Integer
    End Function
End Class
                  
[C#] 
using System.Runtime.InteropServices;
public class Win32 {
    [DllImport("user32.dll", CharSet=CharSet.Unicode, 
               ExactSpelling=true)]
    public static extern int MessageBoxW(int hWnd, String text, String 
                                          caption, uint type);
}
                  
[C++] 
using namespace System::Runtime::InteropServices;
typedef void* HWND;
[DllImport("user32", CharSet=CharSet::Ansi, ExactSpelling=true)]
extern "C" int MessageBoxA(HWND hWnd,
                          String* pText,
                          String* pCaption,
                          unsigned int uType);
                  

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

DllImportAttribute Class | DllImportAttribute Members | System.Runtime.InteropServices Namespace

Show:
© 2014 Microsoft