Bug Summary for Visual Studio (1): GetSelText(), UTC Time issue
The topics in this post include (1) GetSelText() method for CRichEditCtrl class only returns the first character in the selected text in Visual Studio 2003 but it works correctly in Visual Studio 2008; (2) Using of the same copy of code but different time displaying (UTC related) behavior occur between Visual Studio 2003 and Visual Studio 2008; These are all what I have learned from recent trying out of the visual studio IDE while doing some development work.
1. GetSelText() Method for CRichEditCtrl Class only returns the first character.
The phenomenon of this issue looks like this: I need to retrieve the selected text from CRichEditCtrl view, there is a method GetSelText() which does exactly what I want, it works correctly in Visual Studio 2008 but this method only returns the first character from the selected text when I build exactly the same code in Visual Studio 2003.
After searching around, I found this is a bug for Visual Studio 2003 (and maybe for all versions that before Visual Studio 2003) about the ANSI only restriction of GetSelText(). We have to use the following code to do the same task as for GetSelText();
CString strSelectedText; long lStartIndex = 0; long lEndingIndex = 0; GetRichEditCtrl().GetSel(lStartIndex, lEndingIndex); GetRichEditCtrl().GetTextRange(lStartIndex, lEndingIndex, strSelectedText);
PS: the description of the method GetTextRange() from MSDN (CRichEditCtrl::GetTextRange) is quite unclear and very misleading. At first I just thought I should write the code as something like
GetRichEditCtrl().GetTextRange(lStartIndex – 1, lEndingIndex + 1, strSelectedText);
according to the description “The character position index immediately preceding the first character in the range. ” and “The character position immediately following the last character in the range.” about the parameters. But the fact is only the following as indicated in the sample code
GetRichEditCtrl().GetTextRange(lStartIndex, lEndingIndex, strSelectedText);
works correctly! People should be really careful about this!
2. Different Time (UTC related) Displaying Behavior for VS 2003 and 2008
This phenomenon looks like this: I have a copy of code which extracts some FILETIME data in UTC form (rather than local time) and I use FileTimeToLocalFileTime to convert the time into local time (UTC Time plus the time zone difference) , in Visual Studio 2008, it works correctly showing the correct local time I want. However, when I use Visual Studio 2008 to build exactly the same copy of code, it shows the correct local time plus time zone difference. That is, in Visual Studio 2008, the time is converted into local time one more time than in Visual Studio 2003 for exactly the same copy of code!
This problem is really wired and I acutally still cannot find the exact reason to explain it. However, what I can tell is that some system API from Windows for the purpose of Converting Time Data changes their behavior in Visual Studio 2008 than in Visual Studio 2003. (Highly suspious candidate API might be COleDateTime). Or the environment of Visual Studio 2008 would affects the result too. I just bring this up hoping people like me should be careful when changing IDE versions. I will update this when I found the true reason later on.
Summary and Conclusion
In this post include we discussed two kinds of issues related to Visual Studio. That is, (1) GetSelText() method for CRichEditCtrl class only returns the first character in the selected text in Visual Studio 2003 but it works correctly in Visual Studio 2008; (2) Using of the same copy of code but different time displaying (UTC related) behavior occur between Visual Studio 2003 and Visual Studio 2008. We described the phenomenon and tried to explain the reason behind them, we also give solutions to solve these problems.
（转载本站文章请注明作者和出处 烟客旅人 sigmainfy — http://www.sigmainfy.com，请勿用于任何商业用途）