<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Library &#187; Debug</title>
	<atom:link href="http://www.ucosoft.com/tag/debug/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Thu, 22 Jul 2010 05:17:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Solution: Crash in Release build with self-defined message</title>
		<link>http://www.ucosoft.com/solution-crash-in-release-build-with-self-defined-message.html</link>
		<comments>http://www.ucosoft.com/solution-crash-in-release-build-with-self-defined-message.html#comments</comments>
		<pubDate>Tue, 28 Nov 2006 15:05:02 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[Release]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/42.html</guid>
		<description><![CDATA[We often meet such case: I have an application with a modeless dialog. The dialog comes up perfectly in DEBUG build, But in RELEASE build, it crashed. Such problem often occures because of incorrect signature of message handle functions, that included into MFC message map for your CWnd based class.We should very carefully check signatures [...]]]></description>
			<content:encoded><![CDATA[<p>We often meet such case: I have an application with a modeless dialog. The dialog comes up perfectly in DEBUG build, But in RELEASE build, it crashed.</p>
<p><!--adsense--></p>
<p>Such problem often occures because of incorrect signature of message handle functions, that included into MFC message map for your CWnd based class.<br />We should very carefully check signatures such functions in comparision with expected one by MFC library. For example, if you put follow handler into message map</p>
<p><coolcode lang="cpp" linenum="no"><br />
ON_MESSAGE(WM_SOME_USER_MESSAGE, OnMyMessage)<br />
</coolcode></p>
<p>and define OnMyMessage as:</p>
<p><coolcode lang="cpp" linenum="no"><br />
void CMyWnd::OnMyMessage()<br />
{<br />
 //do something<br />
}<br />
</coolcode></p>
<p>this code will be compiled without errors. DEBUG build can work without any problems, but RELEASE will crash besause ON_MESSAGE macro expect follow<br />signature:</p>
<p><coolcode lang="cpp" linenum="no"><br />
LRESULT CMyWnd::OnMyMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)</coolcode></p>
<p>DEBUG build works because stack processing has differences for debug and release builds.</p>
<p>so, the solution is simple:</p>
<p><span id="more-42"></span></p>
<p>Solution 1:&nbsp; modify the&nbsp; message handle functions with the following style and it will be ok.</p>
<p><coolcode lang="cpp" linenum="no"><br />
void CMyWnd::OnMyMessage(WPARAM wParam, LPARAM lParam)<br />
</coolcode></p>
<p>Solution 2:&nbsp; don&#8217;t modify the message handle functios, and change the <font color="#0000ff"><strong>ON_MESSAGE macro </strong><font color="#000000">to</font><strong> </strong></font><font color="#0000ff"><strong>ON_MESSAGE_VOID</strong>.</font><br />
<coolcode lang="cpp" linenum="no"><br />
ON_MESSAGE_VOID(WM_SOME_USER_MESSAGE, OnMyMessage)<br />
</coolcode><br />
<br />This macro is in AfxPriv.h, but is largely undocumented.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/debug" title="Debug" rel="tag">Debug</a>, <a href="http://www.ucosoft.com/tag/message" title="message" rel="tag">message</a>, <a href="http://www.ucosoft.com/tag/release" title="Release" rel="tag">Release</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/solution-crash-in-release-build-with-self-defined-message.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Visual C++ Tips</title>
		<link>http://www.ucosoft.com/microsoft-visual-c-tips-and-tricks2.html</link>
		<comments>http://www.ucosoft.com/microsoft-visual-c-tips-and-tricks2.html#comments</comments>
		<pubDate>Wed, 22 Nov 2006 06:12:20 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/21.html</guid>
		<description><![CDATA[Here are some tips of Microsoft Visual Studio 6.0. Display the LastError&#8217;s value When we want to get the LastError message, we often using the following code. LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER &#124; FORMAT_MESSAGE_FROM_SYSTEM &#124; FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &#038;lpMsgBuf, 0, NULL ); // Process any inserts in lpMsgBuf. // &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some tips of Microsoft Visual Studio 6.0.</p>
<h4><a href="#" rel="bookmark">Display the LastError&#8217;s value</A></h4>
<p>When we want to get the LastError message, we often using the following code.</p>
<p><coolcode lang="cpp" linenum="no"><br />
LPVOID lpMsgBuf;<br />
FormatMessage(<br />
    FORMAT_MESSAGE_ALLOCATE_BUFFER |<br />
    FORMAT_MESSAGE_FROM_SYSTEM |<br />
    FORMAT_MESSAGE_IGNORE_INSERTS,<br />
    NULL,<br />
    GetLastError(),<br />
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language<br />
    (LPTSTR) &#038;lpMsgBuf,<br />
    0,<br />
    NULL<br />
);<br />
// Process any inserts in lpMsgBuf.<br />
// &#8230;<br />
// Display the string.<br />
MessageBox( NULL, (LPCTSTR)lpMsgBuf, &#8220;Error&#8221;, MB_OK | MB_ICONINFORMATION );<br />
// Free the buffer.<br />
LocalFree( lpMsgBuf );<br />
</coolcode><br />
<br />But now VisualSudio 6.0 has provied a virtual Pseudoregister called <coolcode linenum="no">@ERR</coolcode><br />
we can simply input the expression in the watch window and we will get the LastError message.<coolcode linenum="no">@ERR,hr</coolcode>Here is supported pseudoregisters list:<a href="http://www.codeproject.com/debug/pseudoregister.asp">[1]</a><br />
<span id="more-21"></span><br />
<coolcode lang="asm" linenum="no"><br />
@ERR<br />
;Last error value,the same value returned by the GetLastError() API function</p>
<p>@TIB<br />
;Thread information block for the current thread</p>
<p>@CLK<br />
;Undocumented clock register; usable only in the Watch window</p>
<p>@EAX, @EBX, @ECX, @EDX, @ESI, @EDI, @EIP, @ESP, @EBP, @EFL<br />
;Intel CPU registers</p>
<p>@CS, @DS, @ES, @SS, @FS, @GS<br />
;Intel CPU segment registers</p>
<p>@ST0, @ST1, @ST2, @ST3, @ST4, @ST5, @ST6, @ST7<br />
;Intel CPU floating-point registers<br />
</coolcode></p>
<h4><a href="#" rel="bookmark">Acknowledge:</a></h4>
<p><!--adsense--><br />
[1]<a href="http://www.codeproject.com/debug/pseudoregister.asp">An introduction to debugging in MSVC++ using Pseudoregisters </a><br /> <br />
[2]<a href="http://www.highprogrammer.com/alan/windev/visualstudio.html">Microsoft Visual C++ Tips and Tricks </a></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/debug" title="Debug" rel="tag">Debug</a>, <a href="http://www.ucosoft.com/tag/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/microsoft-visual-c-tips-and-tricks2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

