﻿<?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>BlogJava-JafeLee-随笔分类-C++</title><link>http://www.blogjava.net/JafeLee/category/24879.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 15 Oct 2007 05:29:30 GMT</lastBuildDate><pubDate>Mon, 15 Oct 2007 05:29:30 GMT</pubDate><ttl>60</ttl><item><title>用VC的一些问题</title><link>http://www.blogjava.net/JafeLee/archive/2007/10/11/151932.html</link><dc:creator>Jafe</dc:creator><author>Jafe</author><pubDate>Thu, 11 Oct 2007 01:20:00 GMT</pubDate><guid>http://www.blogjava.net/JafeLee/archive/2007/10/11/151932.html</guid><wfw:comment>http://www.blogjava.net/JafeLee/comments/151932.html</wfw:comment><comments>http://www.blogjava.net/JafeLee/archive/2007/10/11/151932.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/JafeLee/comments/commentRss/151932.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JafeLee/services/trackbacks/151932.html</trackback:ping><description><![CDATA[最近做的东西都要用vc，很多错误都莫名， sigh。。。 Java真好！<br />1、error C2146: syntax error : missing ';' before identifier 'ContextRecord'<br />c:\program files\psdk\include\winnt.h(3393) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int<br />c:\program files\psdk\include\winnt.h(3393) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int<br /><br />原因：忘记包含头文件 windows.h了~<br />解决方法：包含头文件  windows.h <br /><img src ="http://www.blogjava.net/JafeLee/aggbug/151932.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JafeLee/" target="_blank">Jafe</a> 2007-10-11 09:20 <a href="http://www.blogjava.net/JafeLee/archive/2007/10/11/151932.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Visual Studio 2005 Express 下的 WinPcap 配置</title><link>http://www.blogjava.net/JafeLee/archive/2007/09/27/148719.html</link><dc:creator>Jafe</dc:creator><author>Jafe</author><pubDate>Thu, 27 Sep 2007 06:55:00 GMT</pubDate><guid>http://www.blogjava.net/JafeLee/archive/2007/09/27/148719.html</guid><wfw:comment>http://www.blogjava.net/JafeLee/comments/148719.html</wfw:comment><comments>http://www.blogjava.net/JafeLee/archive/2007/09/27/148719.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/JafeLee/comments/commentRss/148719.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JafeLee/services/trackbacks/148719.html</trackback:ping><description><![CDATA[因网络课程的作业需要用到winpcap，不得已又要和C++打交道了。由于winpcap是为vc而设计的，但是我又不大喜欢用盗版，于是打算用免费的 VC++ 2005 Express版。<br /><br />1、安装 Visual Studio 2005 Express Edition 和 Paltform SDK。<br /><br />如何安装Visual Studio 2005 Express在这里就不赘述了，很简单的。由于VC Express没有自带 Platform SDK,所以需要自己下载安装（如果不安装 psdk的话，就会出现 找不到 winsock2.h 的编译错误）。由于微软现在官网提供的psdk下载比较麻烦，需要windows正版验证，再加上体积比较大，所以我这里就不用，我用的psdk是在这里下载的：<br /><a href="http://www.microsoft.com/msdownload/platformsdk/sdkupdate/XPSP2FULLInstall.htm">XPSP2 PSDK Full Download with Local Install</a><br />还有一个，不知道能不能安装在xp上，有兴趣的兄弟可以自己试试<br /><a href="http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm">Windows Server 2003 PSDK Full Download with Local Install</a><br />似乎这两个链接在官网上是找不到的<br />下载、解压、安装，然后再配置 VC++：<br />tools --&gt; options  --&gt; Projects and Solutions  --&gt; VC++ Directories   : 把以下路径添加到相应的下拉节点中去：(其中psdk是你的sdk安装目录）<br /><ul><li><p>Executalbe files ：<tt>psdkdir\Bin</tt></p></li><li><p>Include files ：<tt>psdkdir</tt><tt>\include</tt></p></li><li><p>Library files：<tt>psdkdir</tt><tt>\lib</tt></p></li></ul>2、安装 winpcap:到这里下载 <a href="http://www.winpcap.org/install/bin/WinPcap_4_0_1.exe">winpcap</a><br />安装后按要求重启，如果没安装这个包，程序即使编译成功也不能运行，会提示找不到 winpcap.dll<br /><br />3、下载  <a href="http://www.winpcap.org/install/bin/WpdPack_4_0_1.zip">WinPcap Developer's 
						Packs</a><br />解压后会得一个目录WpdPack四个子目录：<br /> docs<br /> Examples-pcap<br /> Examples-remote<br /> Include<br /> Lib<br />然后配置VC++<br />tools --&gt; options  --&gt; Projects and Solutions  --&gt; VC++ Directories :<br /><ul><li><p>Include files ：<tt>WpdPackPath</tt><tt>\include</tt></p></li><li><p>Library files：<tt> WpdPackPath</tt><tt>\lib</tt></p></li></ul>其中 WpdPackPath是目录WpdPack的绝对路径<br /><br />4、新建一个 win32-&gt;win32 console application 工程，然后配置工程属性：<br /><ul><li>右键 -&gt; Properties -&gt; Configuration Properties -&gt; C/C++ -&gt; Preprocessor -&gt; Proprocessor Definition   往上面添加 WPCAP就可以了（这一步不做似乎也没什么问题~)</li><li>右键 -&gt; Properties -&gt; Configuration Properties -&gt; Linker -&gt; input -&gt; Additional Dependencies  往上面添加 wpcap.lib Packet.lib</li></ul>5、一个例子：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><img id="Code_Closed_Image_145434" onclick="this.style.display='none'; Code_Closed_Text_145434.style.display='none'; Code_Open_Image_145434.style.display='inline'; Code_Open_Text_145434.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" height="16" width="11" /><img id="Code_Open_Image_145434" style="display: none;" onclick="this.style.display='none'; Code_Open_Text_145434.style.display='none'; Code_Closed_Image_145434.style.display='inline'; Code_Closed_Text_145434.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" height="16" width="11" /><span id="Code_Closed_Text_145434" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255);"></span><span id="Code_Open_Text_145434" style="display: none;"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">pcap.h</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">remote-ext.h</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> main()<br />{<br />    pcap_if_t </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">alldevs;<br />    pcap_if_t </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">d;<br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> errbuf[PCAP_ERRBUF_SIZE];<br />    <br />    </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Retrieve the device list from the local machine </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> auth is not needed </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">alldevs, errbuf) </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        fprintf(stderr,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Error in pcap_findalldevs_ex: %s\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, errbuf);<br />        exit(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> Print the list </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(d</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> alldevs; d </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> NULL; d</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> d</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">next)<br />    {<br />        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">%d. %s</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">i, d</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">name);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (d</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">description)<br />            printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> (%s)\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, d</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">description);<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />            printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> (No description available)\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (i </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nNo interfaces found! Make sure WinPcap is installed.\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> We don't need any more the device list. Free it </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    pcap_freealldevs(alldevs);<br /><br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}<br /></span></span></div>注意，如果不添加 #include "remote-ext.h" 也是会报错的~<br /><br />6、链接错误：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">anothertest.obj : error LNK2019: unresolved external symbol __imp__WSASetLastError@</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiGetNameInfo@</span><span style="color: rgb(0, 0, 0);">28</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__inet_ntoa@</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiLegacyGetAddrInfo@</span><span style="color: rgb(0, 0, 0);">16</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__htonl@</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiLegacyGetAddrInfo@</span><span style="color: rgb(0, 0, 0);">16</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__getservbyname@</span><span style="color: rgb(0, 0, 0);">8</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiLegacyGetAddrInfo@</span><span style="color: rgb(0, 0, 0);">16</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__htons@</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiLegacyGetAddrInfo@</span><span style="color: rgb(0, 0, 0);">16</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__inet_addr@</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiParseV4Address@</span><span style="color: rgb(0, 0, 0);">8</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__WSAGetLastError@</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiQueryDNS@</span><span style="color: rgb(0, 0, 0);">24</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__gethostbyname@</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiQueryDNS@</span><span style="color: rgb(0, 0, 0);">24</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__gethostbyaddr@</span><span style="color: rgb(0, 0, 0);">12</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiLegacyGetNameInfo@</span><span style="color: rgb(0, 0, 0);">28</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__getservbyport@</span><span style="color: rgb(0, 0, 0);">8</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiLegacyGetNameInfo@</span><span style="color: rgb(0, 0, 0);">28</span><span style="color: rgb(0, 0, 0);"><br />anothertest.obj : error LNK2019: unresolved external symbol __imp__ntohs@</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> referenced </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> function _WspiapiLegacyGetNameInfo@</span><span style="color: rgb(0, 0, 0);">28</span></div>解决该问题，需要只需把ws2_32.lib添加到wpcap.lib Packet.lib后面（见上面第4条）<img src ="http://www.blogjava.net/JafeLee/aggbug/148719.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JafeLee/" target="_blank">Jafe</a> 2007-09-27 14:55 <a href="http://www.blogjava.net/JafeLee/archive/2007/09/27/148719.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>