﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-love in C++, live on MFC-随笔分类-Bug of Today</title><link>http://www.cppblog.com/flyingxu/category/1483.html</link><description>to get ready...</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 13:03:25 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 13:03:25 GMT</pubDate><ttl>60</ttl><item><title>Memory leak in CWinThread?</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 26 Jul 2006 11:11:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/10557.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/10557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/10557.html</trackback:ping><description><![CDATA[
		<p>类似的问题见<a href="http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20084406.html">http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20084406.html</a></p>
		<p>下面的代码，当用AfxBeginThread开始一个线程时，实际上是有内存泄漏的</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font face="Courier New">
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (ii </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; ii </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1000</span>
						<span style="COLOR: #000000">; ii</span>
						<span style="COLOR: #000000">++</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">) <br />{<br />  CWinThread </span>
						<span style="COLOR: #000000">*</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">pWinThread; <br />  pWinThread </span>
						<span style="COLOR: #000000">=</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000"> AfxBeginThread(ThreadLBProc, NULL);<br />  ::Sleep(</span>
						<span style="COLOR: #000000">500</span>
				</font>
				<font face="Courier New">
						<span style="COLOR: #000000">);<br />}<br /><br />UINT ThreadLBProc(LPVOID pParam)<br />{<br />  </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
				</font>
				<span style="COLOR: #000000">
						<font face="Courier New">;<br />}</font>
						<br />
				</span>
		</div>VC输出的典型提示为：<br />Detected memory leaks!<br />Dumping objects -&gt;<br /><font style="BACKGROUND-COLOR: #ffffff"><b style="COLOR: black; BACKGROUND-COLOR: #ffff66"><font style="BACKGROUND-COLOR: #ffffff">thrdcore.cpp</font></b>(</font><font style="BACKGROUND-COLOR: #ffffff">166)</font> : {782} client block at 0x00425300, subtype 0, 112 bytes long.<br />实际上，只要看到是<font style="BACKGROUND-COLOR: #ffff00"><strong>thrdcore.cpp</strong>(166)</font> 的内存泄漏，基本就是同一个原因，和上面的代码一样。<br />解决方法：<br />step 1)<br />在线程函数中，记得写AfxEndThread();(与AfxBeginThread对应，其他的开始线程的函数，有相应的函数)<br />step 2)<br />用::WaitForSingleObject()确保线程彻底退出<br /><br />step 2是比较容易忽略的，用sleep函数只能侥幸的保证线程退出，但不能确保。<img src ="http://www.cppblog.com/flyingxu/aggbug/10557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-26 19:11 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/26/10557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>再调试状态下，按下F12，程序就出错了（VC）</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 13 Jul 2006 10:29:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9818.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9818.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9818.html</trackback:ping><description><![CDATA[用VC调试程序，只要按下F12，程序就出错了，出错的代码还很奇怪，再PeekMessage中，但是只出现在调试（按F5），不出现在全速运行（Ctrl+F5），release版本也没有问题<br />网上的解答:<br /><a href="http://support.microsoft.com/kb/q130667/">http://support.microsoft.com/kb/q130667/</a> F12居然就是这么定义的，ft<br /><br />所以，在定义程序功能的时候，就尽量不要用到F12 ，哈<img src ="http://www.cppblog.com/flyingxu/aggbug/9818.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-13 18:29 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/13/9818.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bug： OnIdle called only while mouse's moving</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Sat, 08 Jul 2006 18:03:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9593.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9593.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9593.html</trackback:ping><description><![CDATA[在mfc的group上有这样一个问题：（<a href="http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&amp;mid=1aa1eddf-7bcf-407b-84fe-234fe0975331&amp;sloc=en-us">http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&amp;mid=1aa1eddf-7bcf-407b-84fe-234fe0975331&amp;sloc=en-us</a>）<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">I need to update one </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> data and the view during the idle, I used </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">  <br />method </span><span style="COLOR: #0000ff">in</span><span style="COLOR: #000000"> the Cdoc:<br /></span><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CMyAppDoc::OnIdle(){<br /><br />    theClass</span><span style="COLOR: #000000">-&gt;</span></font><font face="Courier New"><span style="COLOR: #000000">Update();<br />    POSITION pos </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> GetFirstViewPosition();<br />    CView</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pView </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> GetNextView(pos);<br />    pView</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Invalidate(</span><span style="COLOR: #0000ff">true</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    pView</span><span style="COLOR: #000000">-&gt;</span></font><span style="COLOR: #000000"><font face="Courier New">UpdateWindow();    <br />}</font><br /><br />It works only when I move the mouse, what</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">s wrong? Z_Z</span><span style="COLOR: #000000"><br /></span></div>这个问题的确比较搞，要好好看mfc源码的，下面是我的回答<br />Nothing is wrong, I can explain it  is by design.<br />Please take a look at the source code of int CWinThread::Run(), in that function, IsIdleMessage() is called, and in IsIdleMessage() WM_PAINT is ignored, which means WM_PAINT will not cause OnIdle to be called, for windows think it's just a WM_PAINT message and will not change the UI.<br />Your UpdateWindow() only post a WM_PAINT message, the message queue is not empty but it's ignored by IsIdleMessage(), that's why.<br />But when you move your mouse, the message queue is filled with some WM_MOUSEMOVE and it's not ignored for the position changes. So your OnIdle() is called again.<br />-<br />My suggestion is to move your Invalidate &amp; UpdateWindow code to somewhere else.<br /><font face="Courier New">OnIdle（）</font>的确是个有点复杂的问题，我可能还会写几篇文章 ：）<br />这里（<a href="http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/14f20aa5ffd6994d/66b6e5949a31bfa2?lnk=st&amp;q=AfxUnlockTempMaps&amp;rnum=40&amp;hl=zh-CN#66b6e5949a31bfa2">http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/14f20aa5ffd6994d/66b6e5949a31bfa2?lnk=st&amp;q=AfxUnlockTempMaps&amp;rnum=40&amp;hl=zh-CN#66b6e5949a31bfa2</a>）有篇文章讲的很到位<img src ="http://www.cppblog.com/flyingxu/aggbug/9593.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-09 02:03 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/09/9593.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>_asm int 3 的一个应用：在程序运行后再进入调试器</title><link>http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 06 Jul 2006 09:35:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/9493.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/9493.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/9493.html</trackback:ping><description><![CDATA[调试程序的时候，一般<br />1）启动调试器，比如VC<br />2）在VC中设断点<br />3）操作程序，使得程序运行到断点，停下来<br />但是现在我遇到一个情况，希望调试的情景是这样的：双击某个文件，我的程序启动后，这个时候我想程序停下来，让我在VC中调试它。<br />但是，双击文件后启动的程序，是个独立的exe运行程序，肯定不是在VC的运行控制下的，VC中设置的断点不起作用的。怎么办呢？<br />这个时候可以在想让程序停下来的地方增加指令_asm int 3，debug下编译好。双击文件后运行这个exe，在exe运行到_asm int 3时，就会中断，而把当前的exe运行与一个新的调试器（一个新的VC进程）结合起来。接下来就像一般的调试了。<br />这时的调试步骤类似与：<br />1）程序运行<br />2）遇到特定条件时，_asm int 3把当前exe与一个新的调试器，比如一个新的VC进程，联系起来<br />3）在调试器中调试exe<br /><br />：）<img src ="http://www.cppblog.com/flyingxu/aggbug/9493.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-06 17:35 <a href="http://www.cppblog.com/flyingxu/archive/2006/07/06/9493.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>编译优化选项不匹配引起的一个bug</title><link>http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Fri, 02 Jun 2006 02:32:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/8075.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/8075.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/8075.html</trackback:ping><description><![CDATA[有两个工程,w.exe和c.dll;开始的时候,如果exe是release版本用debug版本的dll时,函数调用会出错,我觉得也可以理解,没有多想.<br />今天遇到一个问题更奇怪,都是debug版本,但是exe和dll的optimizations设置不一样,都会出莫名的错误,出错行更搞笑,是<br />m_ComboBox.AddString(_T("") )<br />怎么查也查不出问题,把优化选项改成一致问题就没有了,搞不懂<img src ="http://www.cppblog.com/flyingxu/aggbug/8075.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-06-02 10:32 <a href="http://www.cppblog.com/flyingxu/archive/2006/06/02/8075.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>错误提示"An unsupported operation was attempted"的原因</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 31 May 2006 09:27:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/7963.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/7963.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/7963.html</trackback:ping><description><![CDATA[编译好了,运行一个程序,试图打开一个对话框时,对话框出不来,反倒是出来一个错误提示:<br />"An unsupported operation was attempted"<br />搜了一下:<a href="http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21023191.html"><br />http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21023191.html</a>里面有回答,的确是那样的,是resource id的问题.<br /><br />错误原因:<br />开始,给一个radio映射了一个变量:<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"><font face="Courier New"> DDX_Radio(pDX, IDC_RADIO1, m_nFindType);</font></span></div>后来发现<u>IDC_RADIO1</u>这个id不好,改为 DDX_Radio(pDX, <u>IDC_RADIO_BIT,</u> m_nFindType);<br />编译当然不会出错,运行时,就出现异常了.如果在上面的代码上设个断点,然后跟踪进去,看的非常清楚.<br /><br /><img src ="http://www.cppblog.com/flyingxu/aggbug/7963.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-31 17:27 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/31/7963.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在OnPaint()使用两次CPaintDC，关于::BeginPaint()/::EndPaint()</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Mon, 22 May 2006 15:39:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/7517.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/7517.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/7517.html</trackback:ping><description><![CDATA[在重载CSplitterWnd中，重载了OnPaint()，<br />默认的代码如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CHideSplitterWnd::OnPaint() <br />{<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> device context for painting<br />    </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> TODO: Add your message handler code here<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Do not call CSplitterWnd::OnPaint() for painting messages</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><font face="Courier New">}</font></span></div>wizard添加的代码居然有这样一行：<font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Do not call CSplitterWnd::OnPaint() for painting messages<font color="#000000">，后面有个猜测。<br /></font></span></font><span style="COLOR: #008000"><font color="#000000">然后我继续写我的函数：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CHideSplitterWnd::OnPaint() <br />{<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> device context for painting<br />    <br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 调用基类，先</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    CSplitterWnd::OnPaint();<br />    <br /></span><span style="COLOR: #008000">     //</span></font><font face="Courier New"><span style="COLOR: #008000">利用dc画一些别的东西，但是实际上，它们永远不会被画出来<br /></span><span style="COLOR: #008000">   //</span><span style="COLOR: #008000">除非不调用基类的OnPaint()</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    m_rectButton.DrawButton(</span><span style="COLOR: #000000">&amp;</span></font><span style="COLOR: #000000"><font face="Courier New">dc);<br />}</font></span></div>结果我添加的东西怎么也不会被画出来，为什么会这样？<br /></font><br /><font color="#000000">看了CSplitterWnd::OnPaint()的代码，发现它也用了一个CPaintDC，而且也是个临时变量<br /></font><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CSplitterWnd::OnPaint()<br />{<br />    ASSERT_VALID(</span><span style="COLOR: #0000ff">this</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">);</span></font></div><font color="#000000">而关键的地方就在CPaintDC的ctor和dtor中了：在CPaintDC的ctor中调用了<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font face="Courier New"><span style="COLOR: #000000">::BeginPaint(m_hWnd </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> pWnd</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">m_hWnd, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m_ps)</span></font></div>而在CPaintDC的dtor中调用了<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font face="Courier New"><span style="COLOR: #000000">::EndPaint(m_hWnd, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m_ps);</span></font></div>而：BeginPaint是开始根据当前的cliprect来画，EndPaint则会清空当前的cliprect。<br /></font><br /><font color="#000000">所以，前面调用基类的OnPaint的过程结束后，当前的cliprect为NULL，所以，第二个CPaintDC在视图画点什么时，cliprect已经为NULL，当然什么也画不上去了 ：）<br /></font><br /><font color="#000000">如果我一定想再用CPaintDC画点什么，怎么办？再次调用InvalidateRect，使得cliprect不为空。</font><br /></span><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff"><font face="Courier New">void</font></span><font face="Courier New"><span style="COLOR: #000000"> CHideSplitterWnd::OnPaint() <br />{<br />    //注意临时变量声明的顺序，因为BeginPaint/EndPaint是不支持嵌套的<br />    //CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span></font><font face="Courier New"><span style="COLOR: #008000"> device context for painting<br />    <br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: Add your message handler code here</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    CSplitterWnd::OnPaint();<br />    <br />    //第二此调用<br />    InvalidateRect(</span><span style="COLOR: #000000">&amp;</span></font><font face="Courier New"><span style="COLOR: #000000">m_rectButton,FALSE);<br />    CPaintDC dc(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 在这里，device context for painting</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    m_rectButton.DrawButton(</span><span style="COLOR: #000000">&amp;</span></font><font face="Courier New"><span style="COLOR: #000000">dc);<br />    <br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Do not call CSplitterWnd::OnPaint() for painting messages</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><font face="Courier New">}</font></span></div>所以，我猜测，所有用了CPaintDC的地方，MFC都会加一句：不要调用基类的函数啦～<br /><br /><font face="Courier New">呵呵，不知道我讲清楚没有</font><img src ="http://www.cppblog.com/flyingxu/aggbug/7517.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-22 23:39 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/22/7517.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>把代码移植成UNICODE</title><link>http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 18 May 2006 08:09:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/7356.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/7356.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/7356.html</trackback:ping><description><![CDATA[
		<h2 style="MARGIN: 12pt 0in 3pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">动机</span>
				<font face="Arial">:</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">在没有装中文字体的机器上显示中文</span>
		</h2>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果不是</span>unicode,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">某些中文字符会在不同的</span>codepage<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上出现乱码</span>;<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果当前</span>codepage<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为韩文时</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">某些中文字会变成韩文的样子</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">奇怪</span>.</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<font face="Arial">Step1: define _UNICODE, undefine _MBCS</font>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">宏定义</span>UNICODE, _UNICODE<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义两个也可以</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义一个也可以</span>,windows<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的头文件会保证两个都会被定义</span>.</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font face="Courier New">
						<span style="COLOR: #000000">#ifdef _UNICODE<br />#ifndef UNICODE<br /></span>
						<span style="COLOR: #0000ff">#define</span>
						<span style="COLOR: #000000"> UNICODE </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> UNICODE is used by Windows headers</span>
				</font>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
				<span style="COLOR: #000000">
						<br />
						<br />
						<font face="Courier New"> <br />#ifdef UNICODE<br />#ifndef _UNICODE<br /></font>
				</span>
				<font face="Courier New">
						<span style="COLOR: #0000ff">#define</span>
						<span style="COLOR: #000000"> _UNICODE        </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> _UNICODE is used by C-runtime/MFC headers</span>
				</font>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">
						<font face="Courier New">#endif</font>
				</span>
		</div>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"> </p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<font face="Arial">Step2: </font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">更改变量类型</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比如</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">char -&gt; TCHAR</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">
						<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">但是</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">,<span lang="ZH-CN">并不是说所有的</span>char<span lang="ZH-CN">类型都不能用了</span>.<span lang="ZH-CN">如果需要用</span>,<span lang="ZH-CN">并且函数的参数</span>/<span lang="ZH-CN">返回值什么的都不冲突</span>,char<span lang="ZH-CN">类型还是可以用的</span>.<o:p></o:p></span>
		</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span style="mso-font-kerning: 0pt">
						<font face="Arial">Step3: </font>
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-font-kerning: 0pt">更改常量字符串形式</span>
				<span style="mso-font-kerning: 0pt">
						<o:p>
						</o:p>
				</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">"</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">" -&gt; _T("</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-fareast-language: EN-US">")</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">因为开始写程序时没有注意</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">,<span lang="ZH-CN">造成这样的常量字符串形式非常多</span>,<span lang="ZH-CN">一个个改起来很烦</span>,<span lang="ZH-CN">我写了个小插件</span>,<span lang="ZH-CN">可以讲</span></span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">”</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">”</span>
				<span lang="ZH-CN" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">选中后点一下</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">button<span lang="ZH-CN">就能变成</span>_T(</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">“</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">abc</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; mso-ascii-font-family: 宋体; mso-font-kerning: 0pt">”</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">),<span lang="ZH-CN">有点用</span>,<span lang="ZH-CN">代码也非常的短</span>.<o:p></o:p></span>
		</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span style="mso-font-kerning: 0pt">
						<font face="Arial">Step4: </font>
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-font-kerning: 0pt">替换某些函数</span>
				<span style="mso-font-kerning: 0pt">
						<o:p>
						</o:p>
				</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比如</span>atoi -&gt; _ttoi</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在这里遇到一个问题</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就是</span>atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的替换</span>.</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按照</span>msdn, atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应该被</span>_ttof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">替换</span></p>
		<table style="mso-cellspacing: 0in" cellspacing="0" cellpadding="0" border="0">
				<tbody>
						<tr>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="17%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>TCHAR.H routine </b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 29%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="29%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>_UNICODE &amp; _MBCS not defined</b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 26%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="26%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>_MBCS defined</b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 28%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="28%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align="center">
												<b>_UNICODE defined</b>
												<b>
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
						</tr>
						<tr>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="17%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>_tstof</b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 29%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="29%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>atof</b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 26%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="26%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>atof </b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 28%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" valign="top" width="28%">
										<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
												<b>_wtof </b>
												<span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial Unicode MS'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是奇怪的是</span>,VC6<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面不认识</span>_tstof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个函数</span>,VC.net 2003<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就可以</span>.</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有两个解决的办法</span>:</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in">1)<span style="FONT: 7pt 'Times New Roman'">      </span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为</span>atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">只是替换为浮点数</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以这里用</span>WideCharToMultiByte<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">转化一下之后再调用</span>atof<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也是可行的</span></p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in">2)<span style="FONT: 7pt 'Times New Roman'">      </span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">呵呵</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用</span>strtod<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的替换函数</span>_tcstod,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">哈哈</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当然参数要变一下,我觉得这个方法不错,不要被msdn限制死了</span></p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<font face="Arial">Step5: </font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">检查一下调用其他</span>
				<font face="Arial">dll</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">的接口函数</span>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为项目还用了另外一个</span>dll,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其中有些接口需要</span>char*<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">参数</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个时候就必须用</span>WideCharToMultiByte<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">转换一下了</span>.<br /><br /><font size="4"><strong>VC里面的设置:</strong></font><br />1) 等把所有的编译error改完了之后一编译,除了个link错误,不过msdn有解释:<br />If you are using Unicode and MFC, you will get an unresolved external on _<b>WinMain@16</b> if you don’t create an entrypoint to <b>wWinMainCRTStartup</b>. Use the /ENTRY option or type this value in the Project Settings dialog box. (To find this option in the development environment, click Settings on the Project menu, then click the Link tab, and click Output in the Category box.) <br /><img src="http://www.codeguru.com/dbfiles/get_image.php?id=10285&amp;lbl=ALIN3_GIF&amp;ds=20050809" /><br />2)终于编译成功了,调试的时候却发现CString的值不能在QuickWatch窗口中显示了<br />tools-&gt;option-&gt;<br />in the debug tab u can find a check box Labeled "Display unicode strings"<br />Check it. <br /></p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">问题</span>
				<font face="Arial">:</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">直接用</span>
				<font face="Arial">ANSI</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">的</span>
				<font face="Arial">dll</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">中的</span>
				<font face="Arial">CString</font>
		</h3>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在使用</span>dll<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的时候</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">需要直接使用</span>dll<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的一个变量</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是</span>CString<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类型</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为这个</span>dll<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">还没有改为</span>unicode,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以在直接使用其变量时有点问题</span>,<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使得值不对</span>.(是不是这个原因还没有完全验证,应该是的)</p>
		<h3 style="MARGIN: 12pt 0in 3pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">到这里</span>
				<font face="Arial">,</font>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">宣布移植失败</span>
				<font face="Arial">!</font>
		</h3>
		<p style="MARGIN: 12pt 0in 3pt">/*补充：<br />结果是失败，但是基本移植代码的所有步骤都有了。而且，也指出了如果需要调用的dll不是unicode，每次调用/传递参数时，都要转换，很烦。<br />后来我把dll的代码也移植了下，现在运行的很好，韩文、中文都可以显示，不管你当前语言是什么。<br />*/</p>
		<p style="MARGIN: 12pt 0in 3pt">还有一篇讲移植步骤的,更全面,适合更复杂的情况:<br />Cheat Sheet:Unicode-enabling Microsoft C/C++ Source Code (<a href="http://www.i18nguy.com/unicode/c-unicode.html">http://www.i18nguy.com/unicode/c-unicode.html</a>)</p>
		<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"> <o:p></o:p></p>
<img src ="http://www.cppblog.com/flyingxu/aggbug/7356.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-18 16:09 <a href="http://www.cppblog.com/flyingxu/archive/2006/05/18/7356.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个不能调试DLL的问题</title><link>http://www.cppblog.com/flyingxu/archive/2006/04/17/5754.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Mon, 17 Apr 2006 07:20:00 GMT</pubDate><guid>http://www.cppblog.com/flyingxu/archive/2006/04/17/5754.html</guid><wfw:comment>http://www.cppblog.com/flyingxu/comments/5754.html</wfw:comment><comments>http://www.cppblog.com/flyingxu/archive/2006/04/17/5754.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyingxu/comments/commentRss/5754.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyingxu/services/trackbacks/5754.html</trackback:ping><description><![CDATA[有两个工程W.exe, 和c.dll<br />每次我从w调试c的时候都是可以直接从w工程设断点,调试进入c源码的.c的源码我有,在另外一个目录下.这是个我觉得很好的功能.<br />结果有一天,我拷了个新的c工程,编译后,发现从w进不了c代码了,即使勉强进去了,居然不是停在函数的第一句,而是在某个循环体内.<br />...<br />...<br />后来看了一下,原来,在w工程的debug目录下,还有个c.lib和c.dll的老版本;而新版的c.lib和c.dll在w工程的根目录下.而调试的时候,debug目录下的dll lib是优先的(猜测)<br />...<br />...<br />所以,只是个粗心的问题,不是技术问题.<img src ="http://www.cppblog.com/flyingxu/aggbug/5754.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyingxu/" target="_blank">flyingxu</a> 2006-04-17 15:20 <a href="http://www.cppblog.com/flyingxu/archive/2006/04/17/5754.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>