<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>工业酒精 &#187; VS2008</title>
	<atom:link href="http://www.alcoholwang.com/tag/vs2008/feed" rel="self" type="application/rss+xml" />
	<link>http://www.alcoholwang.com</link>
	<description></description>
	<lastBuildDate>Thu, 01 Jul 2010 16:22:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>用Visual Studio 2008创建VC++的ISAPI项目</title>
		<link>http://www.alcoholwang.com/create_isapi_project_by_visual_studio_2008.htm</link>
		<comments>http://www.alcoholwang.com/create_isapi_project_by_visual_studio_2008.htm#comments</comments>
		<pubDate>Sun, 26 Oct 2008 16:32:07 +0000</pubDate>
		<dc:creator>工业酒精</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[ISAPI]]></category>
		<category><![CDATA[VS2008]]></category>
		<category><![CDATA[开源]]></category>

		<guid isPermaLink="false">http://www.alcoholwang.com/?p=26</guid>
		<description><![CDATA[&#160; 在VC++ 6.0和VS2003中都有ISAPI的项目向导，用其开发ISAPI是很方便的，但是从Visual Studio 2005开始这个模板就没有了。 &#160; 如何在用Visual Studio 2008创建VC++的ISAPI项目，并且能够编译兼容32位和64位的操作系统的dll？ &#160; 通常情况下我们安装的Visual Studio 2008的VC++都没有包含64位的编译器，所以在创建项目之前，最好先安装64位编译器。 &#160; &#160; 可以通过控制面板-&#62;添加/删除程序-&#62;Visual Studio 2008-&#62;添加/删除功能-&#62;Visual C++-&#62;X64编译器和工具。 &#160; &#160; 接下来我们就可以创建我们ISAPI项目了。 &#160; 1、打开Visual Studio 2008-&#62;文件菜单-&#62;新建-&#62;项目-&#62;其他语言-&#62;Visual C++-&#62;常规-&#62;空项目 &#160; 2、打开解决方案资源管理器视图-&#62;选择项目-&#62;添加新建项-&#62;C++文件(.cpp) 3、根据第二步，再添加一个模块定义文件(.def) &#160; 4、打开模块定义文件(.def)文件，根据需要的ISAPI的不同种类定义不同的模块方法 &#160; ISAPI_Extension LIBRARY Your_ISAPI_Extension_Name EXPORTS GetExtensionVersion HttpExtensionProc ISAPI_Filter LIBRARY Your_ISAPI_Filter_Name EXPORTS GetFilterVersion HttpFilterProc &#160; 5、(如果需要编译64位的ISAPI)打开生成菜单-&#62;配置管理器-&#62;活动解决方案平台:新建-&#62;键入或选择新平台:x64-&#62;从此处选择复制设置:WIN32 6、打开解决方案资源管理器视图-&#62;选择项目-&#62;属性-&#62;配置-&#62;所有配置-&#62;平台-&#62;所有平台 常规-&#62;输出目录:$(SolutionDir)$(PlatformName)\$(ConfigurationName) 常规-&#62;中间目录:$(PlatformName)\$(ConfigurationName) 常规-&#62;配置类型:动态库(.dll) 常规-&#62;MFC使用:使用标准 Windows 库 常规-&#62;字符集:未设置 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alcoholwang.com/create_isapi_project_by_visual_studio_2008.htm"><img class="size-full wp-image-46 alignleft" height="80" alt="" src="http://img.alcoholwang.com/static/2008/10/create_isapi_project_by_visual_studio_2008.gif" width="235" align="left" /></a></p>
<p>&#160;</p>
<p>在VC++ 6.0和VS2003中都有ISAPI的项目向导，用其开发ISAPI是很方便的，但是从Visual Studio 2005开始这个模板就没有了。</p>
<p>&#160;</p>
<p><strong></strong></p>
<p><strong>如何在用Visual Studio 2008创建VC++的ISAPI项目，并且能够编译兼容32位和64位的操作系统的dll？</strong></p>
<p> <span id="more-26"></span>
<p>&#160;</p>
<p>通常情况下我们安装的Visual Studio 2008的VC++都没有包含64位的编译器，所以在创建项目之前，最好先安装64位编译器。</p>
<p>&#160;</p>
<p>&#160;</p>
</p>
<p>可以通过<strong>控制面板</strong>-&gt;<strong>添加/删除程序</strong>-&gt;<strong>Visual Studio 2008</strong>-&gt;<strong>添加/删除功能</strong>-&gt;<strong>Visual C++</strong>-&gt;<strong>X64编译器和工具</strong>。</p>
<p>&#160;</p>
<p><img class="alignnone size-full wp-image-27" title="visual_studio_2008_setup_vcpp_x64" height="501" alt="" src="http://img.alcoholwang.com/static/2008/10/visual_studio_2008_setup_vcpp_x64.jpg" width="323" /></p>
<p>&#160;</p>
<p>接下来我们就可以创建我们ISAPI项目了。</p>
<p>&#160;</p>
<p>1、打开<strong>Visual Studio 2008</strong>-&gt;<strong>文件</strong>菜单-&gt;<strong>新建</strong>-&gt;<strong>项目</strong>-&gt;<strong>其他语言</strong>-&gt;<strong>Visual C++</strong>-&gt;<strong>常规</strong>-&gt;<strong>空项目</strong></p>
<p><strong></strong></p>
<p><img class="alignnone size-full wp-image-28" title="visual_studio_2008_create_isapi_project" height="642" alt="" src="http://img.alcoholwang.com/static/2008/10/visual_studio_2008_create_isapi_project.jpg" width="804" /></p>
<p>&#160;</p>
<p>2、打开<strong>解决方案资源管理器</strong>视图-&gt;选择<strong>项目</strong>-&gt;<strong>添加新建项</strong>-&gt;<strong>C++文件(.cpp)</strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p>3、根据第二步，再添加一个<strong>模块定义文件(.def)</strong></p>
<p><strong></strong></p>
<p><img class="alignnone size-full wp-image-29" title="visual_studio_2008_create_isapi_project_addfile" height="301" alt="" src="http://img.alcoholwang.com/static/2008/10/visual_studio_2008_create_isapi_project_addfile.jpg" width="377" /></p>
<p>&#160;</p>
<p>4、打开<strong>模块定义文件(.def)</strong>文件，根据需要的ISAPI的不同种类定义不同的模块方法</p>
<p>&#160;</p>
<ul>
<li><strong>ISAPI_Extension</strong><br />
<blockquote>
<p>LIBRARY Your_ISAPI_Extension_Name         <br />EXPORTS          <br />GetExtensionVersion          <br />HttpExtensionProc</p>
</blockquote>
</li>
<li><strong>ISAPI_Filter</strong><br />
<blockquote>
<p>LIBRARY Your_ISAPI_Filter_Name</p>
<p>EXPORTS</p>
<p>GetFilterVersion</p>
<p>HttpFilterProc</p>
</blockquote>
</li>
</ul>
<p>&#160;</p>
<p>5、(<span style="color: #ff0000">如果需要编译64位的ISAPI</span>)打开<strong>生成</strong>菜单-&gt;<strong>配置管理器</strong>-&gt;<strong>活动解决方案平台</strong>:<strong>新建</strong>-&gt;<strong>键入或选择新平台</strong>:<strong>x64</strong>-&gt;<strong>从此处选择复制设置:WIN32</strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p>6、打开<strong>解决方案资源管理器</strong>视图-&gt;选择<strong>项目</strong>-&gt;<strong>属性</strong>-&gt;<strong>配置</strong>-&gt;<strong>所有配置</strong>-&gt;<strong>平台</strong>-&gt;<strong>所有平台</strong></p>
<p><strong></strong></p>
<ul>
<li><strong>常规</strong>-&gt;<strong>输出目录</strong>:$(SolutionDir)$(PlatformName)\$(ConfigurationName) </li>
<li><strong>常规</strong>-&gt;<strong>中间目录</strong>:$(PlatformName)\$(ConfigurationName) </li>
<li><strong>常规</strong>-&gt;<strong>配置类型</strong>:动态库(.dll) </li>
<li><strong>常规</strong>-&gt;<strong>MFC使用</strong>:使用标准 Windows 库 </li>
<li><strong>常规</strong>-&gt;<strong>字符集</strong>:未设置 </li>
<li><strong>常规</strong>-&gt;<strong>全程序优化</strong>:使用链接时间代码生成 </li>
<li><strong>C/C++</strong>-&gt;<strong>常规</strong>-&gt;<strong>调试信息格式</strong>:程序数据库(/Zi) </li>
<li>(<span style="color: #ff0000">如果需要编译64位的ISAPI</span>)<strong>C/C++</strong>-&gt;<strong>常规</strong>-&gt;检测64位可移植性问题:是(/Wp64) </li>
<li></li>
</ul>
<p>&#160;</p>
<p><img class="alignnone size-full wp-image-31" title="visual_studio_2008_create_isapi_project_attribute_1" height="563" alt="" src="http://img.alcoholwang.com/static/2008/10/visual_studio_2008_create_isapi_project_attribute_1.jpg" width="770" /></p>
<p>&#160;</p>
<p><img class="alignnone size-full wp-image-32" title="visual_studio_2008_create_isapi_project_attribute_2" height="563" alt="" src="http://img.alcoholwang.com/static/2008/10/visual_studio_2008_create_isapi_project_attribute_2.jpg" width="770" /></p>
<p>&#160;</p>
<p>7、打开C++文件，输入你ISAPI相关的代码(这部分不做详细解释，以后的文章会详述)，这里给段示例代码，用来更改HTTP Header中的Server属性</p>
<p>&#160;</p>
<blockquote><p>#include &lt;windows.h&gt;</p>
<p>#include &lt;stdio.h&gt;</p>
<p>#include &lt;stdlib.h&gt;</p>
<p>#include &lt;httpfilt.h&gt;</p>
<p>DWORD DoSendResponse(HTTP_FILTER_CONTEXT * pfc, HTTP_FILTER_SEND_RESPONSE * pResponse);</p>
<p>BOOL WINAPI __stdcall GetFilterVersion(HTTP_FILTER_VERSION *pVer)</p>
<p>{</p>
<p>pVer-&gt;dwFlags = ( SF_NOTIFY_ORDER_LOW | SF_NOTIFY_SEND_RESPONSE );</p>
<p>pVer-&gt;dwFilterVersion = HTTP_FILTER_REVISION;</p>
<p>strcpy(pVer-&gt;lpszFilterDesc, &quot;Replace Server Header ISAPI filter, Version 1.0&quot;);</p>
<p>return TRUE;</p>
<p>}</p>
<p>DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData)</p>
<p>{</p>
<p>switch (NotificationType)</p>
<p>{</p>
<p>case SF_NOTIFY_SEND_RESPONSE :</p>
<p>return DoSendResponse(pfc, (HTTP_FILTER_SEND_RESPONSE *) pvData);</p>
<p>default :</p>
<p>break;</p>
<p>}</p>
<p>return SF_STATUS_REQ_NEXT_NOTIFICATION;</p>
<p>}     <br />DWORD DoSendResponse(HTTP_FILTER_CONTEXT * pfc,HTTP_FILTER_SEND_RESPONSE * pResponse)</p>
<p>{</p>
<p>BOOL fServer = TRUE;</p>
<p>DWORD dwServerError;</p>
<p>fServer = pResponse-&gt;SetHeader(pfc, &quot;Server:&quot;, &quot;MyWebServer&quot;);</p>
<p>if ( !fServer )</p>
<p>{</p>
<p>dwServerError = GetLastError();</p>
<p>pfc-&gt;pFilterContext = (LPVOID)(DWORD64)pResponse-&gt;HttpStatus;</p>
<p>}</p>
<p>return SF_STATUS_REQ_NEXT_NOTIFICATION;</p>
<p>}</p>
</blockquote>
<p>&#160;</p>
<p>最后你就可以编译你的项目了，如果出现编译错误，可能<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&amp;displaylang=en" target="_self">Windows SDK</a>，安装后增加相应的VC++引用即可。</p>
<p>&#160;</p>
<p>你也可以<a href="http://img.alcoholwang.com/static/2008/10/isapi.zip">下载示例项目</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alcoholwang.com/create_isapi_project_by_visual_studio_2008.htm/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
