DllImportAttribute.CharSet フィールド

定義

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

public: System::Runtime::InteropServices::CharSet CharSet;
public System.Runtime.InteropServices.CharSet CharSet;
val mutable CharSet : System.Runtime.InteropServices.CharSet
Public CharSet As 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);
    }
}
Imports System.Runtime.InteropServices

Module Example

    ' Use DllImport to import the Win32 MessageBox function.
    <DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
    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

注釈

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

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

適用対象

こちらもご覧ください