FindNLSStringEx

Locates a Unicode string (wide characters) or its equivalent in another Unicode string for a locale specified by name.

Caution

Because strings with very different binary representations can compare as identical, this function can raise certain security concerns. For more information, see the discussion of comparison functions in Security Considerations: International Features.

Syntax

int FindNLSStringEx(
         LPCWSTR lpLocaleName,
         DWORD dwFindNLSStringFlags,
         _In_reads_(cchSource)LPCWSTR lpStringSource,
         int cchSource,
         _In_reads_(cchValue)LPCWSTR lpStringValue,
         int cchValue,
         LPINT pcchFound,
         LPNLSVERSIONINFO lpVersionInformation,
         LPVOID lpReserved,
         LPARAM sortHandle
)  

Parameters

lpLocaleName
Type: LPCWSTR 

Pointer to a locale name, or one of the following predefined values.

dwFindNLSStringFlags
Type: DWORD 

Flags specifying details of the find operation. These flags are mutually exclusive, with FIND_FROMSTART being the default. The application can specify just one of the find flags with any of the filtering flags defined in the next table. If the application does not specify a flag, the function uses the default comparison for the specified locale. As discussed in Handling Sorting in Your Applications, there is no binary comparison mode.The application can use the filtering flags defined below in combination with a find flag.

lpStringSource
Type: In_reads(cchSource)LPCWSTR 

Pointer to the source string, in which the function searches for the string specified by lpStringValue.

cchSource
Type: int 

Size, in characters excluding the terminating null character, of the string indicated by lpStringSource. The application cannot specify 0 or any negative number other than -1 for this parameter. The application specifies -1 if the source string is null-terminated and the function should calculate the size automatically.

lpStringValue
Type: In_reads(cchValue)LPCWSTR 

Pointer to the search string, for which the function searches in the source string.

cchValue
Type: int 

Size, in characters excluding the terminating null character, of the string indicated by lpStringValue. The application cannot specify 0 or any negative number other than -1 for this parameter. The application specifies -1 if the search string is null-terminated and the function should calculate the size automatically.

pcchFound
Type: LPINT 

Pointer to a buffer containing the length of the string that the function finds. The string can be either longer or shorter than the search string. If the function fails to find the search string, this parameter is not modified.The function can retrieve NULL in this parameter. In this case, the function makes no indication if the length of the found string differs from the length of the source string. Note that the value of pcchFound is often identical to the value provided in cchValue, but can differ in the following cases:

lpVersionInformation
Type: LPNLSVERSIONINFO 

Reserved; must be NULL.

lpReserved
Type: LPVOID 

Reserved; must be NULL.

sortHandle
Type: LPARAM 

Reserved; must be 0.

Return value

Type: int 

Returns a 0-based index into the source string indicated by lpStringSource if successful. In combination with the value in pcchFound, this index provides the exact location of the entire found string in the source string. A return value of 0 is an error-free index into the source string, and the matching string is in the source string at offset 0.

The function returns -1 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:

Remarks

This function provides a variety of search options, including search direction, character equivalence filtering, and locale-specific filtering. Note that equivalence depends on the locale and flags specified in the call to the function. The filtering flags can alter the results of the search. For example, the potential matches increase when the function ignores case or diacritic marks when performing the search.

By default, this function maps the lowercase “i” to the uppercase “I”, even when the Locale parameter specifies Turkish (Turkey) or Azeri (Azerbaijan). To override this behavior for Turkish or Azeri, the application should specify NORM_LINGUISTIC_CASING. If this flag is specified for the correct locale, “ı” (lowercase dotless I) is the lowercase form of “I” (uppercase dotless I) and “i” (lowercase dotted I) is the lowercase form of “ı” (uppercase dotted I).

For many scripts (notably Latin scripts), NORM_IGNORENONSPACE coincides with LINGUISTIC_IGNOREDIACRITIC and NORM_IGNORECASE coincides with LINGUISTIC_IGNORECASE, with the following exceptions:

In contrast to other NLS API functions, which return 0 for failure, this function returns -1 if it fails. On success, it returns a 0-based index. Use of this index helps the function avoid off-by-one errors and one-character buffer overruns.

This function is one of the few NLS functions that calls SetLastError even when it succeeds. It makes this call to clear the last error in a thread when it fails to match the search string. This clears the value returned by GetLastError.

Beginning in Windows 8: If your app passes language tags to this function from the Windows.Globalization namespace, it must first convert the tags by calling ResolveLocaleName.

Requirements

Header: Declared in winnls.h.

Library: Use kernelx.lib.