I have an application built on Windows 7 SP1 Visual Studio 2010 SP1.
It seems CompareString
doesn't work the same way on Windows 7 and Windows XP. I am creating an EndsWith
/StartsWith
-like (See C# String.EndsWith
) methods, but where it works on Windows 7 as expected, but not on Windows XP.
Here are my StartsWith
and EndsWith
:
bool String::StartsWith( const String& value, bool bCaseSensitive ) const
{
if(this->strLen == 0 || value.strLen == 0)
return false;
DWORD flags;
if(bCaseSensitive == false)
flags = LINGUISTIC_IGNORECASE;
else
flags = NORM_LINGUISTIC_CASING;
if( CSTR_EQUAL == CompareStringW(LOCALE_USER_DEFAULT, flags, this->_str, static_cast<int>(value.strLen), value._str, static_cast<int>(value.strLen)) )
return true;
else if(CSTR_EQUAL == CompareStringW(LOCALE_SYSTEM_DEFAULT, flags, this->_str, static_cast<int>(value.strLen), value._str, static_cast<int>(value.strLen)))
return true;
else if(CSTR_EQUAL == CompareStringW(GetThreadLocale(), flags, this->_str, static_cast<int>(value.strLen), value._str, static_cast<int>(value.strLen)))
return true;
else
return false;
}
bool String::EndsWith( const String& value, bool bCaseSensitive ) const
{
if(this->strLen == 0 || value.strLen == 0)
return false;
DWORD flags;
if(bCaseSensitive == false)
flags = LINGUISTIC_IGNORECASE;
else
flags = NORM_LINGUISTIC_CASING;
size_t maxLen;
if(this->strLen < value.strLen)
maxLen = this->strLen;
else
maxLen = value.strLen;
LPCWSTR szStartOffset;
if(maxLen == this->strLen)
szStartOffset = this->_str;
else
szStartOffset = (this->_str + (this->strLen - value.strLen));
if( CSTR_EQUAL == CompareStringW(LOCALE_USER_DEFAULT, flags, szStartOffset, static_cast<int>(maxLen), value._str, static_cast<int>(maxLen)) )
return true;
else if(CSTR_EQUAL == CompareStringW(LOCALE_SYSTEM_DEFAULT, flags, szStartOffset, static_cast<int>(maxLen), value._str, static_cast<int>(maxLen)))
return true;
else if(CSTR_EQUAL == CompareStringW(GetThreadLocale(), flags, szStartOffset, static_cast<int>(maxLen), value._str, static_cast<int>(maxLen)))
return true;
else
return false;
}
If somebody could help me I'd be very grateful.