The Locale Explorer: CompareString

Back To Tips Page

Back to LocaleExplorer

One of several comparison operators can be chosen.  The results will be quite different depending on the comparison mechanism chosen.  The CompareString API is the most general and locale-aware.  However, the options for _tcscmp, _tcsicmp,lstrcmp, and lstrcmpi are all selectable.  Whenever these calls are used, the thread locale that is set will be the thread locale selected, so the runtime libraries are using the same parameters that you would expect to have used by a program running in that locale.  For example, the code that implements _tcscmp is equivalent to that shown below (some details have been omitted since they are irrelevant to this discussion, such as the fact that the locale is actually set outside the loop to avoid a lot of APIs going on inside the loop).

LCID oldlcid = ::GetThreadLocale();

// _tcscmp
    if(c_UseTcsCmp.GetCheck() == BST_CHECKED)
       { /* tcscmp */
        int result = _tcscmp(p1, p2);
        return result;
       } /* tcscmp */

Notice that this screen resembles the LCMapString page.  This is not coincidence; the CLCMapString screen is a derived class of the CCompareString class.

Here are several comparisons

U.S. English, no flags
_tcscmp _tcsicmp lstrcmp lstrcmpi

Note that there is no apparent difference between lstrcmp and lstrcmpi.

[Dividing Line Image]

The views expressed in these essays are those of the author, and in no way represent, nor are they endorsed by, Microsoft.

Send mail to with questions or comments about this web site.
Copyright 2005 Joseph M. Newcomer/FlounderCraft Ltd.  All Rights Reserved.
Last modified: May 14, 2011