getstringtypeex (kernel32)
Last changed: -65.82.123.169

.
Summary
The GetStringTypeEx API returns character information for the characters in the specified string pointer. Three types of character information can be retrieved, depending on the dwInfoType parameter.

C# Signature:

[DllImport("kernel32.dll")]
static extern bool GetStringTypeEx(uint Locale, uint dwInfoType,
   string lpSrcStr, int cchSrc, [Out] ushort [] lpCharType);

VB Signature:

Private Declare Unicode Function GetStringTypeEx Lib "kernel32" Alias "GetStringTypeExW" ( _
  ByVal Locale As Int32, ByVal dwInfoType As Int32, _
  ByVal lpSrcStr As String, ByVal cchSrc As Int32, _
  ByRef lpCharType As Int16) As Boolean

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Public Const CT_TYPE1 As Int32 = &H1    ' Retrieves character type info
Public Const CT_TYPE2 As Int32 = &H2    ' Retrieves bi-directional layout info
Public Const CT_TYPE3 As Int32 = &H4    ' Retrieves text processing info

Public Enum CharTypeInfo As Integer
    AnsiPosix = CT_TYPE1
    BidirectionalLayout = CT_TYPE2
    TextProcessing = CT_TYPE3
End Enum

Public Function GetStringTypeEx(ByVal str As String, ByVal cti As CharTypeInfo) As Int16()

    Dim APIRetVal As Boolean
     Dim CharTypeInfoArray(Len(str) - 1) As Int16

     ' No need to specify the Locale, the Unicode (W) version of GetStringTypeEx ignores it anyway
     APIRetVal = GetStringTypeEx(0, cti, str, Len(str), CharTypeInfoArray(0))

     If (Not APIRetVal) Then
             Throw New ApplicationException("GetStringTypeExError")
     End If

     Return CharTypeInfoArray

End Function

Alternative Managed API:

Do you know one? Please contribute it!

Documentation