DllImportAttribute.CharSet 欄位

定義

指示如何將字串參數封送處理到方法和控制項函式名稱改變 (Name Mangling)。

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.NoneCharSet.Ansi ,相當於 。 在 Visual Basic 中 Declare ,您會使用 語句來指定 CharSet 欄位。

欄位 ExactSpelling 會影響欄位的行為 CharSet ,以判斷要叫用的進入點名稱。 如需與欄位相關聯的 CharSet 字串封送處理和名稱比對行為的詳細描述和範例,請參閱 指定字元集

適用於

另請參閱