DllImportAttribute.CharSet フィールド

定義

文字列パラメーターをメソッドにマーシャリングし、名前マングルを制御する方法を示します。

public System.Runtime.InteropServices.CharSet CharSet;

フィールド値

次のコード例は、 DllImportAttribute 属性を使用して Win32 MessageBox 関数をインポートする方法を示しています。 次に、このコード例では、インポートされたメソッドを呼び出します。

using System;
using System.Runtime.InteropServices;

class Example
{
    // Use DllImport to import the Win32 MessageBox function.
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    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);
    }
}

注釈

このフィールドを列挙体のメンバーと共に使用して、文字列パラメーターの CharSet マーシャリング動作を指定し、呼び出すエントリ ポイント名 (指定された正確な名前、または "A" または "W" で終わる名前) を指定します。 C# と Visual Basic の既定の列挙メンバーは であり CharSet.Ansi 、C++ の既定の列挙メンバーは CharSet.Noneです。これは と CharSet.Ansi同じです。 Visual Basic では、 ステートメントを Declare 使用してフィールドを CharSet 指定します。

フィールドは ExactSpelling 、呼び出すエントリ ポイント名を CharSet 決定する際のフィールドの動作に影響します。 フィールドに関連付 CharSet けられている文字列マーシャリングと名前の一致動作の詳細な説明と例については、「 文字セットの指定」を参照してください。

適用対象

製品 バージョン
.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, 10
.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

こちらもご覧ください