About BhashaIndia | Contribute | SiteMap | Register | Sign in to Windows Live ID
  Developers Patrons
Hindi Tamil Kannada Gujarati Marathi Telugu Bengali Malayalam Punjabi Konkani Oriya Sanskrit Nepali
Home > Developers > KnowHow > CollationIntro > Windows API Welcome Guest!

Windows API

By Cathy Wissink & Michael S.Kaplan - Windows Globalization,Microsoft Corporation

Collation is something that, ideally, people will not notice when it is working well. Whether they are looking at the WAB (Windows Address Book) in Microsoft's Outlook Express or the files in a Windows Explorer listview, users will not think twice about the order if it is culturally correct. If it is wrong, however, they will definitely notice the problem.

You can actually see how radically collation can change in the user experience by changing your user locale (for example, on Windows through Regional Options in the Control Panel) to a locale that sorts differently than your ordering expectations. Even doing this for short periods of time will highlight how strange the system seems when it is “out of order.”

Windows does tend to simplify this type of issue by supplying APIs like lstrcmp:

int lstrcmp(
LPCTSTR lpString1, // first string
LPCTSTR lpString2 // second string
);

This function takes two null-terminated strings and returns -1, 0, or 1 depending on whether the first string would sort before, identical with, or after the second string. The comparison follows the user's cultural preferences, matching their chosen user locale. Similarly, there is an lstrcmpi function:

int lstrcmpi(
LPCTSTR lpString1, // first string
LPCTSTR lpString2 // second string
);

The lstrcmpi function exists to do case insensitive comparisons of two strings and is otherwise identical to lstrcmp. APIs such as these allow a developer to do standard copying operations without having to worry too much about the larger issues of collation.

Sometimes simple functions like lstrcmp and lstrcmpi are not enough, and a more detailed or customized string comparison function is needed. For this, Windows provides functions that take a locale parameter such as CompareString. Additionally CompareString lets you alter other collation behavior when you need to. In many cases, however, lstrcmp and lstrcmpi can do everything you need.

Partner Profile | Privacy Statement | Why Passport | Testimonials
This site uses Unicode for non-English characters and uses Open Type fonts.
©2003-2007 Microsoft Corporation. All rights reserved.