次の方法で共有


LCIDConversionAttribute クラス

メソッドのアンマネージ シグネチャにロケール識別子 (LCID) パラメータが必要であることを示します。

この型のすべてのメンバの一覧については、LCIDConversionAttribute メンバ を参照してください。

System.Object
   System.Attribute
      System.Runtime.InteropServices.LCIDConversionAttribute

<AttributeUsage(AttributeTargets.Method)>
NotInheritable Public Class LCIDConversionAttribute   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Method)]
public sealed class LCIDConversionAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Method)]
public __gc __sealed class LCIDConversionAttribute : public   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Method)
class LCIDConversionAttribute extends Attribute

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

この属性は、メソッドに適用できます。

この属性は、マーシャラが、指定されたメソッド引数の後に LCID を渡すことを要求することを示します。マネージ コードからアンマネージ コードへの呼び出しが行われるときに、マーシャラが引数 LCID を自動的に指定します。

使用例

[Visual Basic, C#, C++] LCIDConversionAttribute に指定されるさまざまな値に応じて、シグネチャが変化するようすを次の例に示します。

 

Imports System
Imports System.Runtime.InteropServices
Imports System.Reflection

Class LCIDAttrSampler

    Const LCID_INSTALLED As Integer = 1
    Const LCID_SUPPORTED As Integer = 2

    <DllImport("KERNEL32.DLL", EntryPoint:="IsValidLocale", _
    SetLastError:=True, CharSet:=CharSet.Unicode, _
    CallingConvention:=CallingConvention.StdCall), _
    LCIDConversionAttribute(0)> _
    Public Shared Function IsValidLocale(ByVal dwFlags As Integer) As Boolean
    End Function

    Public Sub CheckCurrentLCID()
        Dim mthIfo As MethodInfo = Me.GetType().GetMethod("IsValidLocale")
        Dim attr As Attribute = Attribute.GetCustomAttribute(mthIfo, GetType(LCIDConversionAttribute))

        If Not(attr Is Nothing) Then
            Dim lcidAttr As LCIDConversionAttribute = CType(attr, LCIDConversionAttribute)
            Console.WriteLine("Position of the LCID argument in the unmanaged signature: " + lcidAttr.Value.ToString())
        End If

        Dim res As Boolean = IsValidLocale(LCID_INSTALLED)
        Console.WriteLine("Result LCID_INSTALLED " + res.ToString())
        res = IsValidLocale(LCID_SUPPORTED)
        Console.WriteLine("Result LCID_SUPPORTED " + res.ToString())
    End Sub

    Public Shared Sub Main()
        Dim smpl As LCIDAttrSampler = New LCIDAttrSampler()
        smpl.CheckCurrentLCID()
    End Sub

End Class


[C#] 
using System;
using System.Runtime.InteropServices;
using System.Reflection;

class LCIDAttrSample
{
    private const int LCID_INSTALLED = 1;
    private const int LCID_SUPPORTED = 2;

    [DllImport("KERNEL32.DLL", EntryPoint="IsValidLocale", SetLastError = true, CharSet = CharSet.Auto)]
    [LCIDConversionAttribute(0)] // Position of the LCID argument
    public static extern bool IsValidLocale(
                                                uint dwFlags            // options
                                            );

    public void CheckCurrentLCID()
    {
        MethodInfo mthIfo = this.GetType().GetMethod("IsValidLocale");
        Attribute attr = Attribute.GetCustomAttribute(mthIfo,typeof(LCIDConversionAttribute));

        if( attr != null)
        {
            LCIDConversionAttribute lcidAttr = (LCIDConversionAttribute)attr;
            Console.WriteLine("Position of the LCID argument in the unmanaged signature: " + lcidAttr.Value.ToString());
        }

        bool res = IsValidLocale(LCID_INSTALLED);
        Console.WriteLine("Result LCID_INSTALLED " + res.ToString());
        res = IsValidLocale(LCID_SUPPORTED);
        Console.WriteLine("Result LCID_SUPPORTED " + res.ToString());
    }

    static void Main(string[] args)
    {
        LCIDAttrSample smpl = new LCIDAttrSample();
        smpl.CheckCurrentLCID();
    }
}


[C++] 


using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Reflection;

#define LCID_INSTALLED 1
#define LCID_SUPPORTED 2


__gc class LCIDAttrSample
    {

    public:

     [DllImport(S"KERNEL32.DLL", EntryPoint=S"IsValidLocale", SetLastError = true, CharSet = CharSet::Auto)]
        [LCIDConversionAttribute(0)] // Position of the LCID argument
    static bool IsValidLocale(int dwFlags); // options

     void CheckCurrentLCID()
        {
               MethodInfo* mthIfo = this->GetType()->GetMethod(S"IsValidLocale");

               Attribute*  attr = Attribute::GetCustomAttribute(mthIfo, __typeof(LCIDConversionAttribute));

                if (attr != 0) {
                    LCIDConversionAttribute *lcidAttr = dynamic_cast<LCIDConversionAttribute*>(attr);
                    Console::WriteLine(S"Position of the LCID argument in the unmanaged signature: {0}",__box(

lcidAttr->Value));
                }

                bool res = IsValidLocale(LCID_INSTALLED);
                Console::WriteLine(S"Result LCID_INSTALLED {0}",__box( res));
                res = IsValidLocale(LCID_SUPPORTED);
                Console::WriteLine(S"Result LCID_SUPPORTED {0}",__box( res));
        }
     };



    int main()
    {
            LCIDAttrSample *smpl = new LCIDAttrSample();
            smpl->CheckCurrentLCID();

        };

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Runtime.InteropServices

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

LCIDConversionAttribute メンバ | System.Runtime.InteropServices 名前空間