出现“Expression Buffer too small"的错误提示.
上网查找了下,说可能是CString::Format这个函数出现的问题.
例如这句代码:
m_strFBL.Format("%s(放大约%d倍)", m_strFBL, m_nfbl / m_nScreenDPI);
Format中的参数为m_strFBL字符串本身,我估计是Format在内部根据格式化参数列表会对字符串本身的内存空间进行重新分配,而如果直接采用字符串本身作为参数传入的话,这个过程中就会造成内存的冲突,而这个冲突是无法预见的,查看了下msdn,微软也作了相应的注释:
The call will fail if the string object itself is offered as a parameter to
Format
. For example, the following code:
CString str = "Some Data";
str.Format("%d%d", str, 123); //Attention: str is also used in the parameter list.
will cause unpredictable results.
所以为了避免这种无法预见的问题,我们最好不要采取将字符串本身作为参数作为Format的参数,可以另外定义一个CString变量:
CString str;
str.Format(Format("%s(放大约%d倍)", m_strFBL, m_nfbl / m_nScreenDPI);
这样问题就解决了。