Problems with the expression GetUserAttribute(IDS_MYATTRIBUTE) == "1"
The problem is that GetUserAttribute returns const CString&
and therefore the expression
style.GetUserAttribute(IDS_MYATTRIBUTE) == "1"
evaluates to FALSE because s is converted to a LPCTSTR and C++ only compares the pointers but not the contents of the string.
You can see the same behavior if you take a look at the following statement
const CString& xgets(CString s) { return s; }
CString s = "1";
ASSERT(xgets(s) == "1");
The statement will assert.
If you do instead return a CString
CString xgets(CString s) { return s; }
CString s = "1";
ASSERT(xgets(s) == "1");
C++ converts "1" to a CString instead and the statement will not assert.
To work around the problem use the following lines instead:
a) call
if (atoi(colstyle.GetUserAttribute(IDS_MYATTRIBUTE).GetValue())==1)
b) call
if (colstyle.GetUserAttribute(IDS_MYATTRIBUTE).GetValue()==(CString) "1")
c) or simply call
if (colstyle.GetUserAttribute(IDS_MYATTRIBUTE)==(CString) "1")