﻿<?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++博客-日日勤作息-随笔分类-错误处理</title><link>http://www.cppblog.com/zealsoft/category/1555.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 24 Apr 2009 15:55:12 GMT</lastBuildDate><pubDate>Fri, 24 Apr 2009 15:55:12 GMT</pubDate><ttl>60</ttl><item><title>如何用Visual Studio 2005编译Wireshark的插件 </title><link>http://www.cppblog.com/zealsoft/archive/2009/04/24/81002.html</link><dc:creator>zealsoft</dc:creator><author>zealsoft</author><pubDate>Fri, 24 Apr 2009 15:26:00 GMT</pubDate><guid>http://www.cppblog.com/zealsoft/archive/2009/04/24/81002.html</guid><wfw:comment>http://www.cppblog.com/zealsoft/comments/81002.html</wfw:comment><comments>http://www.cppblog.com/zealsoft/archive/2009/04/24/81002.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zealsoft/comments/commentRss/81002.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zealsoft/services/trackbacks/81002.html</trackback:ping><description><![CDATA[<p>今天尝试用Visual Studio 2005编译以前用Visual Studio 2003编译成功过的一个Wireshark插件，生成后发现居然无法在官方的Wireshark中加载插件。在<strong>&nbsp;</strong><a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=4280199"><strong><u><font color=#638f27>KenThompson</font></u></strong></a>的&#8220;<span class=ArticleTopTitle id=ctl00_ArticleTopHeader_ArticleTitle>Creating Your Own Custom Wireshark Dissector</span>&#8221;一文中提到使用Visual Studio 2005编译生成的插件只能在使用Visual Studio 2005生成的Wireshark版本中测试。使用自己采用Visual Studio 2005生成的Wireshark版本测试，发现确实可以，而官方的就不行了。使用Dependency Walker看了看，发现使用Visual Studio 2005生成的DLL文件需要使用MSVCR80.DLL，而官方的Wireshark使用的是MSVCRT.DLL，两者不兼容，所以会出现错误。在微软的网站上可以找到<a href="http://msdn.microsoft.com/en-us/library/ms235591.aspx"><u><font color=#6faf30>解决的方法</font></u></a>：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mt.exe &#8211;manifest MyLibrary.dll.manifest -outputresource:MyLibrary.dll;2 </p>
<p>将这样处理后的DLL再拷贝到官方的Wireshark的插件目录中就可以了。不过采用Visual Studio 2005生成的插件要分发时必须同时分发<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&amp;displaylang=en"><u><font color=#6faf30>Visual Studio 2005的C语言运行库</font></u></a>，看来不如Visual Studio 2003方便。</p>
<img src ="http://www.cppblog.com/zealsoft/aggbug/81002.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zealsoft/" target="_blank">zealsoft</a> 2009-04-24 23:26 <a href="http://www.cppblog.com/zealsoft/archive/2009/04/24/81002.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>运行Google CTemplate首页的例子遇到_CrtIsValidHeapPointer异常 </title><link>http://www.cppblog.com/zealsoft/archive/2008/08/30/60429.html</link><dc:creator>zealsoft</dc:creator><author>zealsoft</author><pubDate>Sat, 30 Aug 2008 04:41:00 GMT</pubDate><guid>http://www.cppblog.com/zealsoft/archive/2008/08/30/60429.html</guid><wfw:comment>http://www.cppblog.com/zealsoft/comments/60429.html</wfw:comment><comments>http://www.cppblog.com/zealsoft/archive/2008/08/30/60429.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/zealsoft/comments/commentRss/60429.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zealsoft/services/trackbacks/60429.html</trackback:ping><description><![CDATA[<p>最近打算使用<a href="http://code.google.com/p/google-ctemplate/"><u><font color=#6faf30>Google CTemplate</font></u></a>作为模板引擎，但是运行其主页上的例子居然出现了错误。程序运行的结果正常，但是在退出时导致了<font face=Verdana><font face=Verdana>_CrtIsValidHeapPointer异常，主要是释放string变量时出现了错误。搜索了一下Google CTemplate的讨论组，说如果编译库文件所使用的CRT版本和编译程序所使用的CRT版本不一致会导致这个问题。DLL库采用的CRT是多线程DLL方式的，所以应用程序也必须使用这个方式，这就需要在应用程序的工程选项中将CRT由默认的单线程方式改为多线程DLL方式。如下图所示。</font></font></p>
<p><img alt="" src="http://images.cnblogs.com/cnblogs_com/zealsoft/crt.png" border=0></p>
<p>&nbsp;</p>
<p>不过这有时不太方便，也可以把CTemplate所需要的文件直接加到工程中，好在文件不多：</p>
<ul>
    <li><font face=Verdana>src\base\arena.cc</font>
    <li><font face=Verdana>src\htmlparser\htmlparser.cc</font>
    <li><font face=Verdana>src\htmlparser\jsparser.cc</font>
    <li><font face=Verdana>src\windows\port.cc</font>
    <li><font face=Verdana>src\htmlparser\statemachine.c</font><font face=Verdana>c</font>
    <li><font face=Verdana>src\template.cc</font>
    <li><font face=Verdana>src\template_dictionary.cc</font>
    <li><font face=Verdana>src\template_from_string.cc</font>
    <li><font face=Verdana>src\template_modifiers.cc</font>
    <li><font face=Verdana>src\template_namelist.cc</font>
    <li><font face=Verdana>src\template_pathops.cc</font>
    <li>
    <li></li>
</ul>
<p>记得在这些文件的编译属性中选择&#8220;<font face=Verdana>不使用预编译头</font>&#8221;，否则会出现编译错误。<br><br><img height=20 src="http://www.cppblog.com/Emoticons/QQ/lucky.gif" width=19 border=0>2008年8月31日：以上介绍的是0.90版本，在0.91版本中<font face=Verdana>src\template_from_string.cc</font> 文件不存在了。 <br><img height=20 src="http://www.cppblog.com/Emoticons/QQ/lucky.gif" width=19 border=0>2008年9月15日：采用上面介绍的方法有个缺陷，就是会出现很多编译和链接的警告C4251和LNK4049、LNK4071。这主要是因为在CTemplate的代码中，定义了： </p>
<p><font face=Verdana>&nbsp;</p>
<div class=cnblogs_code><img id=Code_Closed_Image_101917 style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_101917').style.display='none'; document.getElementById('Code_Open_Image_101917').style.display='inline'; document.getElementById('Code_Open_Text_101917').style.display='inline';" height=16 src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><img id=Code_Open_Image_101917 style="DISPLAY: inline" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_101917').style.display='none'; getElementById('Code_Closed_Image_101917').style.display='inline'; getElementById('Code_Closed_Text_101917').style.display='inline';" height=16 src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><span class=cnblogs_code_Collapse id=Code_Closed_Text_101917 style="DISPLAY: none">Code</span><span id=Code_Open_Text_101917 style="DISPLAY: inline"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #000000">#ifndef&nbsp;CTEMPLATE_DLL_DECL<br>#&nbsp;define&nbsp;CTEMPLATE_DLL_DECL&nbsp;&nbsp;__declspec(dllimport)<br></span><span style="COLOR: #0000ff">#endif</span></span></div>
<p>所以需要在编译的命令行加上&#8220;<font face=Verdana>/D CTEMPLATE_DLL_DECL=&#8221;。</font></font></p>
<img src ="http://www.cppblog.com/zealsoft/aggbug/60429.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zealsoft/" target="_blank">zealsoft</a> 2008-08-30 12:41 <a href="http://www.cppblog.com/zealsoft/archive/2008/08/30/60429.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>TAU G2的错误信息：TSC0134: Transition must end with stop, nextstate or join action. </title><link>http://www.cppblog.com/zealsoft/archive/2007/02/08/18547.html</link><dc:creator>zealsoft</dc:creator><author>zealsoft</author><pubDate>Thu, 08 Feb 2007 09:48:00 GMT</pubDate><guid>http://www.cppblog.com/zealsoft/archive/2007/02/08/18547.html</guid><wfw:comment>http://www.cppblog.com/zealsoft/comments/18547.html</wfw:comment><comments>http://www.cppblog.com/zealsoft/archive/2007/02/08/18547.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zealsoft/comments/commentRss/18547.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zealsoft/services/trackbacks/18547.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">
						<a href="http://www.telelogic.com.cn/products/tau/g2/index.cfm">TAU G2</a>
				</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">的错误信息常常显得很诡异。不但帮助中找不到，而且字面的意思也不准确。今天又遇到一个：</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">
						<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">text.ttp<span style="mso-tab-count: 1">       </span>Error<span style="mso-tab-count: 1">          </span>TSC0134: Transition must end with stop, nextstate or join action. GUID: *gUWtVDd*H5LUiy6sEYVQFxL<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">从字面的意思看，和状态图有关。但仔细检查以后，发现状态图没有错误，实际上是一个函数中忘了加</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">return</span>
				<span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">语句了。</span>
				<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">
						<o:p>
						</o:p>
				</span>
		</p>
<img src ="http://www.cppblog.com/zealsoft/aggbug/18547.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zealsoft/" target="_blank">zealsoft</a> 2007-02-08 17:48 <a href="http://www.cppblog.com/zealsoft/archive/2007/02/08/18547.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>卸载Intel C++ Compiler后Visual C++ 6.0不能工作了</title><link>http://www.cppblog.com/zealsoft/archive/2006/06/13/8501.html</link><dc:creator>zealsoft</dc:creator><author>zealsoft</author><pubDate>Tue, 13 Jun 2006 07:59:00 GMT</pubDate><guid>http://www.cppblog.com/zealsoft/archive/2006/06/13/8501.html</guid><wfw:comment>http://www.cppblog.com/zealsoft/comments/8501.html</wfw:comment><comments>http://www.cppblog.com/zealsoft/archive/2006/06/13/8501.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/zealsoft/comments/commentRss/8501.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zealsoft/services/trackbacks/8501.html</trackback:ping><description><![CDATA[
		<p>前段时间觉得好玩，安装了Intel C++ Compiler进行评估，现在评估结束了，决定卸载。开始卸载之后，Visual C++ 6.0开始罢工了，报告无法找到xicl6.exe进行编译。搜索了下注册表，发现Intel C++ Compiler在安装时候修改了Visual C++的工具设置，但卸载时没有恢复。可以修改下面两个地方：<br />1、HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Build System\Components\Platforms\Win32 (x86)\Tools\32-bit C/C++ Compiler for 80×86\Executable Path改成cl.exe；<br />2、HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Build System\Components\Platforms\Win32 (x86)\Tools\COFF Linker for 80×86\Executable Path改成link.exe就可以了。<br />需要退出VC++ 6.0，然后重新启动，一切就正常了。 </p>
<img src ="http://www.cppblog.com/zealsoft/aggbug/8501.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zealsoft/" target="_blank">zealsoft</a> 2006-06-13 15:59 <a href="http://www.cppblog.com/zealsoft/archive/2006/06/13/8501.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Borland Developer Studio (BDS) 2006打开C++Builder工程出现Access Violation错误</title><link>http://www.cppblog.com/zealsoft/archive/2006/05/03/6606.html</link><dc:creator>zealsoft</dc:creator><author>zealsoft</author><pubDate>Wed, 03 May 2006 14:36:00 GMT</pubDate><guid>http://www.cppblog.com/zealsoft/archive/2006/05/03/6606.html</guid><wfw:comment>http://www.cppblog.com/zealsoft/comments/6606.html</wfw:comment><comments>http://www.cppblog.com/zealsoft/archive/2006/05/03/6606.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zealsoft/comments/commentRss/6606.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zealsoft/services/trackbacks/6606.html</trackback:ping><description><![CDATA[使用Borland Developer Studio (BDS) 2006打开一个C++Builder工程，出现Access Violation错误：<br /><p><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">+ $6[22B5B07D]{bcbide100.bpl} XMLProj.XMLProj.CreateNewBdsPro<wbr>jFile (Line 1249, "..\cpp\XMLProj.pas" + 2) + $6<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">+ $0[51F06B47]{rtl100.bpl  } System.System.@HandleAnyExcepti<wbr>on (Line 9980, "system.pas" + 13) + $0<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $41[7C923786]{ntdll.dll   } RtlConvertUlongToLargeInteger + $41<br /></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $9[7C92EAF5]{ntdll.dll   } KiUserExceptionDispatcher + $9<br /></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $22[22B251E6]{bcbide100.bpl} CppProjOpts.CppProjOpts<wbr>.MakeBprToBdsProj (Line 7414, "CppProjOpts.pas" + 8) + $22<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $24[22B2564C]{
<script><!--
D(["mb","bcbide100.bpl}\nCppProjOpts.CppProjOpts<wbr>.TCppLegacyProjectFileHandler<wbr>.Convert (Line 7637,\n&quot;CppProjOpts.pas&quot; + 11) + $24</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\"> + $9[22B257A8]{bcbide100.bpl}\nCppProjOpts.CppProjOpts<wbr>.TCppLegacyProjectFileHandler<wbr>.FileOpen (Line 7676,\n&quot;CppProjOpts.pas&quot; + 1) + $9</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\"> + $14[20C347A4]{coreide100.bpl}\nDocModul.DocModul.TFilterList<wbr>.OpenFile (Line 777, &quot;DocModul.pas&quot; +\n35) + $14</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\"> + $1E[20C39572]{coreide100.bpl}\nDocModul.DocModul.ProjectOpenDi<wbr>alog (Line 3079, &quot;DocModul.pas&quot; + 30)\n+ $1E</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\">[00412CC7]{bds.exe     }</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\"> + $3[218AD460]{vclactnband100.bpl}\nActnMenus.ActnMenus.TCustomActi<wbr>onMainMenuBar.TrackMenu (Line 3143,\n&quot;ActnMenus.pas&quot; + 3) + $3</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\"> + $4[218A891D]{vclactnband100.bpl}\nActnMenus.ActnMenus.TCustomActi<wbr>onMenuBar.CMItemClicked (Line 883,\n&quot;ActnMenus.pas&quot; + 3) + $4</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\"> + $6[5203C998]{vcl100.bpl \n} Controls.Controls.TWinControl<wbr>.WndProc (Line 7242, &quot;Controls.pas&quot; +\n101) + $6</span></p>
\n\n
<p><span lang\u003d\"EN-US\" style\u003d\"font-size:9.0pt;font-family:Arial\"> + $4[218AA158]{vclactnband100.bpl}\nActnMenus.ActnMenus.TCustomActi<wbr>onMenuBar.WndProc (Line 1572, &quot;ActnMenus.pas&quot;\n+ 15) + $4</span></p>
\n\n
<p>",1]
);
//--></script>
 bcbide100.bpl} CppProjOpts.CppProjOpts<wbr>.TCppLegacyProjectFileHandler<wbr>.Convert (Line 7637, "CppProjOpts.pas" + 11) + $24<br /></wbr></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $9[22B257A8]{bcbide100.bpl} CppProjOpts.CppProjOpts<wbr>.TCppLegacyProjectFileHandler<wbr>.FileOpen (Line 7676, "CppProjOpts.pas" + 1) + $9<br /></wbr></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $14[20C347A4]{coreide100.bpl} DocModul.DocModul.TFilterList<wbr>.OpenFile (Line 777, "DocModul.pas" + 35) + $14<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $1E[20C39572]{coreide100.bpl} DocModul.DocModul.ProjectOpenDi<wbr>alog (Line 3079, "DocModul.pas" + 30) + $1E<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">[00412CC7]{bds.exe     }<br /></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $3[218AD460]{vclactnband100.bpl} ActnMenus.ActnMenus.TCustomActi<wbr>onMainMenuBar.TrackMenu (Line 3143, "ActnMenus.pas" + 3) + $3<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $4[218A891D]{vclactnband100.bpl} ActnMenus.ActnMenus.TCustomActi<wbr>onMenuBar.CMItemClicked (Line 883, "ActnMenus.pas" + 3) + $4<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $6[5203C998]{vcl100.bpl  } Controls.Controls.TWinControl<wbr>.WndProc (Line 7242, "Controls.pas" + 101) + $6<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $4[218AA158]{vclactnband100.bpl} ActnMenus.ActnMenus.TCustomActi<wbr>onMenuBar.WndProc (Line 1572, "ActnMenus.pas" + 15) + $4<br /></wbr></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $0[51F40BB0]{rtl100.bpl  } Classes.Classes.StdWndProc (Line 11572, "classes.pas" + 8) + $0<br /></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $6F[77D18706]{USER32.dll  } GetDC + $6F<br /></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $14F[77D187E6]{USER32.dll  } GetDC + $14F<br /></span><span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"> + $122[77D189A0]{USER32.dll  } GetWindowLongW + $122<br /></span> + $A[77D1BCC7]{USER32.dll  } DispatchMessageA + $A<br /><br />经过检查，发现BDS2006只能处理C++Builder 5/6的工程，而早期的工程文件由于不是XML格式，就会导致上面的错误。而要想处理早期的工程，必须先用BCB 6.0转换一下。</p><img src ="http://www.cppblog.com/zealsoft/aggbug/6606.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zealsoft/" target="_blank">zealsoft</a> 2006-05-03 22:36 <a href="http://www.cppblog.com/zealsoft/archive/2006/05/03/6606.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>添加了CSpreadSheet.h后出现LNK2005错误</title><link>http://www.cppblog.com/zealsoft/archive/2006/04/24/6181.html</link><dc:creator>zealsoft</dc:creator><author>zealsoft</author><pubDate>Mon, 24 Apr 2006 07:24:00 GMT</pubDate><guid>http://www.cppblog.com/zealsoft/archive/2006/04/24/6181.html</guid><wfw:comment>http://www.cppblog.com/zealsoft/comments/6181.html</wfw:comment><comments>http://www.cppblog.com/zealsoft/archive/2006/04/24/6181.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zealsoft/comments/commentRss/6181.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zealsoft/services/trackbacks/6181.html</trackback:ping><description><![CDATA[
		<p>一个朋友来信说，他在工程中添加了一个数据导出到Excel表的类CSpreadSheet，结果出现了LNK2005的错误。在网上查了一下，发现还不只我这个朋友遇到这个问题，CSDN上也有类似问题：<a href="http://topic.csdn.net/t/20050311/09/3842070.html" target="_blank"><strong><font color="#676767" size="1">http://topic.csdn.net/t/20050311/09/3842070.html</font></strong></a><br />这个CSpreadSheet.h文件在<a href="http://www.codeproject.com/database/cspreadsheet.asp" target="_blank"><strong><font color="#676767" size="1">CodeProject</font></strong></a>和<a href="http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c4307/" target="_blank"><strong><font color="#676767" size="1">CodeGuru</font></strong></a>上都有，其实是这个文件有问题。这个头文件既包括了CSpreadSheet类的定义，还包括这个类的实现，这样所有包含这个头文件的类都有一份这个类的实现，链接的时候自然就出错了。只要工程中有两个以上的地方包含这个头文件就会出现这个错误。解决的办法很简单，建立一个CSpreadSheet.cpp文件，然后在这个文件的开头加上：<br /></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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include “stdafx.h”<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include “CSpreadSheet.h”</span>
		</div>
		<p>然后把CSpreadSheet.h中的从“// Open spreadsheet for reading and writing”（含）到“#endif”（不含）之前的语句都<strong>剪切</strong>到CSpreadSheet.cpp中，也就是将类的声明和实现分离，再将CSpreadSheet.cpp文件加到工程中，这样就可以了。 </p>
<img src ="http://www.cppblog.com/zealsoft/aggbug/6181.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zealsoft/" target="_blank">zealsoft</a> 2006-04-24 15:24 <a href="http://www.cppblog.com/zealsoft/archive/2006/04/24/6181.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>