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

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/some-useful-shortcut-of-visual-studio-6.html" title="Some useful shortcut of Visual Studio 6 (November 30, 2006)">Some useful shortcut of Visual Studio 6</a> (0)</li>
	<li><a href="http://www.ucosoft.com/visual-sourcesafe-microsofts-source-destruction-system.html" title="Some comment about Visual SourceSafe (November 21, 2006)">Some comment about Visual SourceSafe</a> (0)</li>
	<li><a href="http://www.ucosoft.com/solution-crash-in-release-build-with-self-defined-message.html" title="Solution: Crash in Release build with self-defined message (November 28, 2006)">Solution: Crash in Release build with self-defined message</a> (0)</li>
	<li><a href="http://www.ucosoft.com/make-the-code-completion-working-again-in-vc-60.html" title="Make the Code Completion working again in VC++ 6.0 (December 6, 2006)">Make the Code Completion working again in VC++ 6.0</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-enable-profile-in-vc-6.html" title="How to enable &#8220;profile&#8221; in Visual C++ 6.0 (December 28, 2006)">How to enable &#8220;profile&#8221; in Visual C++ 6.0</a> (1)</li>
	<li><a href="http://www.ucosoft.com/ccommodule-in-porting-atl-dll-project-to-vc8.html" title="CComModule in porting ATL DLL project to VC8 (June 22, 2007)">CComModule in porting ATL DLL project to VC8</a> (0)</li>
</ul>

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