<?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; Release</title>
	<atom:link href="http://www.ucosoft.com/tag/release/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>
	</channel>
</rss>

