<?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>Mon, 19 Jul 2010 04:51:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</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 />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/write-and-read-binary-data-in-variant.html" title="Write and read binary data in VARIANT (November 22, 2006)">Write and read binary data in VARIANT</a> (0)</li>
	<li><a href="http://www.ucosoft.com/what-is-the-usage-of-wm_null.html" title="What is the usage of WM_NULL? (November 23, 2006)">What is the usage of WM_NULL?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/ucogrid-a-great-grid-control-of-mfc.html" title="ucoGrid, a great grid control of MFC (November 26, 2006)">ucoGrid, a great grid control of MFC</a> (18)</li>
	<li><a href="http://www.ucosoft.com/sscanf-with-cstring.html" title="sscanf with CString (March 20, 2007)">sscanf with CString</a> (3)</li>
	<li><a href="http://www.ucosoft.com/simple-code-to-create-an-emf-or-bitmap-file-from-existed-draw-code.html" title="Simple code to create an EMF or Bitmap file from existed draw code (December 16, 2006)">Simple code to create an EMF or Bitmap file from existed draw code</a> (0)</li>
	<li><a href="http://www.ucosoft.com/simple-cedit-validation.html" title="Simple CEdit Validation (June 27, 2007)">Simple CEdit Validation</a> (0)</li>
	<li><a href="http://www.ucosoft.com/moving-selection-of-clistctrl.html" title="Moving selection of CListCtrl (December 3, 2006)">Moving selection of CListCtrl</a> (0)</li>
	<li><a href="http://www.ucosoft.com/microsoft-visual-c-tips-and-tricks2.html" title="Microsoft Visual C++ Tips (November 21, 2006)">Microsoft Visual C++ Tips</a> (0)</li>
	<li><a href="http://www.ucosoft.com/intermittent-work-in-ui-thread-2.html" title="Intermittent work in UI thread (October 16, 2007)">Intermittent work in UI thread</a> (0)</li>
	<li><a href="http://www.ucosoft.com/intermittent-work-in-ui-thread.html" title="Intermittent work in UI thread (October 16, 2007)">Intermittent work in UI thread</a> (0)</li>
</ul>

]]></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>
