DllImportAttribute.ExactSpelling フィールド
DllImportAttribute.CharSet フィールドで、指定された名前以外のエントリ ポイント名をアンマネージ DLL から共通言語ランタイムに検索させるかどうかを制御します。
Public ExactSpelling As Boolean
[C#]
public bool ExactSpelling;
[C++]
public: bool ExactSpelling;
[JScript]
public var ExactSpelling : Boolean;
解説
false の場合、文字 A が追加されたエントリ ポイントの名前が DllImportAttribute.CharSet フィールドを CharSet.Ansi に設定したときに呼び出され、文字 W が追加されたエントリ ポイントの名前が DllImportAttribute.CharSet フィールドを CharSet.Unicode に設定したときに呼び出されます。通常、このフィールドはマネージ コンパイラによって設定されます。プログラミング言語が課す既定値を基に、 CharSet フィールドと ExactSpelling フィールドの関係を次の表に示します。既定値はオーバーライドできますが、オーバーライドするときは慎重に行ってください。
言語 | 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 |
使用例
[Visual Basic, C#, C++] 場合によっては、Visual Basic の開発者は、マネージ コードで DLL 関数を定義する際、 Declare ステートメントを使用する代わりに、 DllImportAttribute を使用します。 ExactSpelling フィールドの設定は、このような事例の 1 つです。
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard
参照
DllImportAttribute クラス | DllImportAttribute メンバ | System.Runtime.InteropServices 名前空間