LCMapString

This content has moved to another location. See LCMapString for the latest version.

Tags :


Community Content

Shawn Steele [MSFT]
LCMapStringEx is preferred

LCMapStringEx is preferred

Try to avoid LCIDs and use locale names if possible

Users can create custom locales which your application may not have access to if it doesn't use the locale name. Custom locales don't get their own LCIDs, so functionality is limited if your application relies on the LCID. See this blog http://blogs.msdn.com/shawnste/pages/custom-cultures-vista-custom-locales.aspx for more info about locales/custom locales and good behavior with locales.

Tags :

Shawn Steele [MSFT]
Upon failure don't trust the output buffer.
After failure the output buffer may not contain any results, even partial results and its contents should be considered invalid.
Tags :

Shawn Steele [MSFT]
The LCMAP_SortKey option as described above wasn't intended to be parsed.

Note that the sort key wasn't ever designed to be parsed or undone, so there are edge cases and the like that would make a dependency on the sort key structure scary. It is safe to know that its null terminated, but that's about all you can take for granted.

I also wouldn't ever use byte reveral with a sort key :)

Tags :

Shawn Steele [MSFT]
To compare sort keys you'd have to do something like this:

Sort keys are basically binary arrays of bytes. You have to be careful about the lengths when testing them. The first byte difference is the actual difference between keys. If one is a substring of the other, then the shorter one sorts first.

int CompareSortKeys(PBYTE key1, size_t length1, PBYTE key2, size2 length2)
{
int result;
// Test only the portion that overlaps
int testLength = min(length1, length2);
int result = memcmp(key1, key2, testLength);
// If one is a substring of the other, the longer one is greater
if (result == 0)
{
// Longer one is greater
if (length1 < length2) return CSTR_LESS_THAN;
if (length2 > length1) return CSTR_GREATER_THAN;
// Otherwise equal
Return CSTR_EQUAL;
}
// Not equal
return result < 0 ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
}


(I HAVEN’T TESTED THE EXAMPLE ABOVE)

Tags :

Page view tracker