LCIDConversionAttribute Classe

Definizione

Indica che la firma non gestita di un metodo prevede un parametro di ID impostazioni locali (LCID).

public ref class LCIDConversionAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
public sealed class LCIDConversionAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class LCIDConversionAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)>]
type LCIDConversionAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type LCIDConversionAttribute = class
    inherit Attribute
Public NotInheritable Class LCIDConversionAttribute
Inherits Attribute
Ereditarietà
LCIDConversionAttribute
Attributi

Esempio

Nell'esempio seguente vengono illustrate diverse traduzioni delle firme in base a valori diversi forniti a LCIDConversionAttribute.

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

#define LCID_INSTALLED 1
#define LCID_SUPPORTED 2

ref class LCIDAttrSample
{
public:

   // Position of the LCID argument

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

   void CheckCurrentLCID()
   {
      MethodInfo^ mthIfo = this->GetType()->GetMethod( "IsValidLocale" );
      Attribute^ attr = Attribute::GetCustomAttribute( mthIfo, LCIDConversionAttribute::typeid );
      if ( attr != nullptr )
      {
         LCIDConversionAttribute^ lcidAttr = dynamic_cast<LCIDConversionAttribute^>(attr);
         Console::WriteLine( "Position of the LCID argument in the unmanaged signature: {0}", lcidAttr->Value );
      }

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

int main()
{
   LCIDAttrSample^ smpl = gcnew LCIDAttrSample;
   smpl->CheckCurrentLCID();
}
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();
    }
}

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

Commenti

È possibile applicare questo attributo ai metodi.

Questo attributo indica che il marshalling deve prevedere che un LCID venga passato dopo l'argomento del metodo designato. Quando le chiamate vengono eseguite da gestito a codice non gestito, il marshalling fornisce automaticamente l'argomento LCID.

Costruttori

LCIDConversionAttribute(Int32)

Inizializza una nuova istanza della classe LCIDConversionAttribute con la posizione del LCID nella firma non gestita.

Proprietà

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)
Value

Ottiene la posizione dell'argomento LCID nella firma non gestita.

Metodi

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per l'istanza.

(Ereditato da Attribute)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a