DllImportAttribute.CharSet フィールド
アセンブリ: mscorlib (mscorlib.dll 内)


CharSet 列挙体のメンバと併せてこのフィールドを使用すると、文字列パラメータのマーシャリング動作と、呼び出すエントリ ポイントの名前 (指定と厳密に一致する名前または "A" か "W" で終わる名前) を指定できます。C# および Visual Basic の既定の列挙体メンバは CharSet.Ansi です。C++ の既定の列挙体メンバは CharSet.None (CharSet.Ansi と等価) です。Visual Basic では、Declare ステートメントを使用して CharSet フィールドを指定します。
ExactSpelling フィールドによって、呼び出すエントリ ポイント名を判定する際の CharSet フィールドの動作が影響を受けます。CharSet フィールドに関連する文字列マーシャリングと名前一致の動作の詳細と例については、「文字セットの指定」を参照してください。

DllImportAttribute 属性を使用して Win32 MessageBox 関数をインポートする方法を次のコード例に示します。このコード例では、インポートしたメソッドを呼び出しています。
Imports System Imports System.Runtime.InteropServices Module Example ' Use DllImport to import the Win32 MessageBox function. <DllImport("user32.dll", CharSet:=CharSet.Auto)> _ Function MessageBox(ByVal hwnd As IntPtr, ByVal t As String, ByVal caption As String, ByVal t2 As UInt32) As Integer End Function Sub Main() ' Call the MessageBox function using platform invoke. MessageBox(New IntPtr(0), "Hello World!", "Hello Dialog", 0) End Sub End Module
using System; using System.Runtime.InteropServices; class Example { // Use DllImport to import the Win32 MessageBox function. [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type); static void Main() { // Call the MessageBox function using platform invoke. MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDllImportAttribute.CharSet フィールドを検索する場合は、下記のリンクをクリックしてください。

- DllImportAttribute.CharSet フィールドのページへのリンク