Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

LCIDConversionAttribute Class

Indicates that a method's unmanaged signature expects a locale identifier (LCID) parameter.

For a list of all members of this type, see LCIDConversionAttribute Members.

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

[Visual Basic]
<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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

You can apply this attribute to methods.

This attribute indicates that the marshaler should expect an LCID to be passed after the designated method argument. When calls are made from managed to unmanaged code, the marshaler supplies the LCID argument automatically.

Example

[Visual Basic, C#, C++] The following example demonstrates different signature translations based on different values supplied to LCIDConversionAttribute.

[Visual Basic] 

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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

LCIDConversionAttribute Members | System.Runtime.InteropServices Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.