DllImportAttribute.CharSet フィールド
この記事の内容
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
文字列パラメーターをメソッドにマーシャリングし、名前マングルを制御する方法を示します。
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
けられている文字列マーシャリングと名前の一致動作の詳細な説明と例については、「 文字セットの指定」を参照してください。
製品 | バージョン |
---|---|
.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 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。