⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch18.htm

📁 VC使用大全。里面集合了VC使用的各种使用技巧。非常有用。
💻 HTM
📖 第 1 页 / 共 3 页
字号:
other functions.</p>
</ul>
<p>The header file XCMC.H declares a number of structures used to hold the information that is passed to these functions. For example, recipient information is kept in this structure:</p>
<pre><font 
color="#008000">/*RECIPIENT*/</font></pre>
<pre><font color="#008000">typedef struct {</font></pre>
<pre><font color="#008000">    CMC_string              name;</font></pre>
<pre><font color="#008000">    CMC_enum                name_type;</font></pre>

<pre><font color="#008000">    CMC_string              address;</font></pre>
<pre><font color="#008000">    CMC_enum                role;</font></pre>
<pre><font color="#008000">    CMC_flags               recip_flags;</font></pre>
<pre><font 
color="#008000">    CMC_extension FAR       *recip_extensions;</font></pre>
<pre><font color="#008000">} CMC_recipient;</font></pre>
<p>You could fill this structure with the name and address of the recipient of a mail message by using a standard dialog 
box or by hard-coding the entries, like this:</p>
<pre><font color="#008000">CMC_recipient recipient = {</font></pre>
<pre><font color="#008000">    &quot;Kate Gregory&quot;,</font></pre>
<pre><font color="#008000">    CMC_TYPE_INDIVIDUAL,</font></pre>

<pre><font color="#008000">    &quot;SMTP:kate@gregcons.com&quot;,</font></pre>
<pre><font color="#008000">    CMC_ROLE_TO,</font></pre>
<pre><font color="#008000">    CMC_RECIP_LAST_ELEMENT,</font></pre>
<pre><font color="#008000">    NULL };</font></pre>

<p>The type, role, and flags use one of these predefined values:</p>
<p><i>Listing 18.1 (excerpt from \MSDev\Include\XCMC.H) Command definitions./* NAME TYPES */</i></p>
<p>#define CMC_TYPE_UNKNOWN                    ((CMC_enum) 0)</p>
<p>#define 
CMC_TYPE_INDIVIDUAL                 ((CMC_enum) 1)</p>
<p>#define CMC_TYPE_GROUP                      ((CMC_enum) 2)</p>
<p>/* ROLES */</p>
<p>#define CMC_ROLE_TO                         ((CMC_enum) 0)</p>
<p>#define CMC_ROLE_CC                         
((CMC_enum) 1)</p>
<p>#define CMC_ROLE_BCC                        ((CMC_enum) 2)</p>
<p>#define CMC_ROLE_ORIGINATOR                 ((CMC_enum) 3)</p>
<p>#define CMC_ROLE_AUTHORIZING_USER           ((CMC_enum) 4)</p>
<p>/* RECIPIENT FLAGS */</p>
<p>#define 
CMC_RECIP_IGNORE                    ((CMC_flags) 1)</p>
<p>#define CMC_RECIP_LIST_TRUNCATED            ((CMC_flags) 2)</p>
<pre><font color="#008000">#define CMC_RECIP_LAST_ELEMENT              ((CMC_flags) 0x80000000)</font></pre>
<p>There is a message 
structure you could fill in the same way, or by presenting the user with a dialog box to enter the message details. This structure includes a pointer to the recipient structure you have already filled. Your program then calls <font 
color="#008000">cmc_logon()</font>, <font color="#008000">cmc_send()</font>, and <font color="#008000">cmc_logoff()</font> to complete the process.</p>
<p><b> Extended MAPI</b></p>
<p>Extended MAPI is based on COM, the OLE Component Object Model. Messages, 
recipients, and many other entities are defined as objects rather than as C structures. There are far more object types in Extended MAPI than there are structure types in CMC. Access to these objects is through OLE (ActiveX) interfaces. The objects expose 
properties, methods, and events. These concepts are discussed in Part IV, <a href="index14.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index14.htm" target="text">Chapter 14</a>, &quot;ActiveX Concepts.&quot;</p>
<p><b> OLE Messaging</b></p>
<p>If you understand Automation (described in <a href="index16.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index16.htm" 
target="text">Chapter 16</a>, &quot;Building an Automation Server&quot;), then you will easily understand OLE Messaging. Your application must be an Automation client, however, and building such a client is beyond the scope of this chapter. Some ways to 
use OLE Messaging are in Visual Basic programming and VBA scripts for programs like Excel. Your program would set up objects and then set their exposed properties (for example, the subject line of a message object) and invoke their exposed methods (for 
example, the <font color="#008000">Send()</font> method of a message object).</p>
<p>The objects used in OLE Messaging include the following:</p>
<ul>
<li> Session</p>
<li> Message</p>
<li> Recipient</p>
<li> Attachment</p>
</ul>
<p>A detailed reference of 
these objects, as well as their properties and methods, can be found in Visual C++ Books Online (the help files) from within Developer Studio. Follow the Books Online hierarchy: SDKs, Win32 SDK, Win32 Messaging (MAPI), OLE Messaging Library.</p>

<h3><b>Using New Internet Classes in Visual C++ 4.2</b></h3>
<p>MFC 4.2 introduced a number of new classes that eliminated the need to learn socket programming when your applications need to access standard Internet client services. Figure 18.4 shows the 
way these classes relate to each other. Collectively known as the WinInet classes, they are the following:</p>
<b><a href="tfigs04.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch18/tfigs04.gif">FIG. 18.4</a></b>
<p><i>The WinInet classes make writing Internet client programs easier.</i></p>
<ul>
<li> 
<font color="#008000">CInternetSession</font></pre>
<li> <font color="#008000">CInternetConnection</font></pre>
<li> <font color="#008000">CInternetFile</font></pre>
<li> <font color="#008000">HttpConnection</font></pre>
<li> <font 
color="#008000">CHttpFile</font></pre>
<li> <font color="#008000">CGopherFile</font></pre>
<li> <font color="#008000">CFtpConnection</font></pre>
<li> <font color="#008000">CGopherConnection</font></pre>
<li> <font color="#008000">CFileFind</font></pre>

<li> <font color="#008000">CFtpFileFind</font></pre>
<li> <font color="#008000">CGopherFileFind</font></pre>
<li> <font color="#008000">CGopherLocator</font></pre>
<li> <font color="#008000">CInternetException</font></pre>
</ul>
<blockquote><p><img 
src="tip.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/tip.gif">
<p>These classes help you write Internet <i>client</i> applications, with which users interact directly. If you want to write <i>server</i> applications, which interact with client applications, you'll be interested in ISAPI, discussed in 
the next section.</p>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<p>First, your program establishes a session by creating a <font color="#008000">CInternetSession</font>. Then, if you have a Uniform Resource Locator (URL) to a Gopher, FTP, or Web (HTTP) 
resource, you can call that session's <font color="#008000">OpenURL()</font> function to retrieve the resource as a read-only <font color="#008000">CInternetFile</font>. Your application can read the file using <font color="#008000">CStdioFile</font> 
functions and manipulate that data in whatever way you need.</p>
<p>If you do not have a URL or do not want to retrieve a read-only file, you proceed differently after establishing the session. You make a connection with a specific protocol by calling the 
session's <font color="#008000">GetFtpConnection()</font>, <font color="#008000">GetGopherConnection()</font>, or <font color="#008000">GetHttpConnection()</font> functions, which return the appropriate connection object. You then call the connection's 
<font color="#008000">OpenFile()</font> function. <font color="#008000">CFtpConnection::OpenFile()</font> returns a <font color="#008000">CInternetFile</font>; <font color="#008000">CGopherConnection::OpenFile()</font> returns a <font 
color="#008000">CGopherFile</font>; and <font color="#008000">CHttpConnection::OpenFile()</font> returns a <font color="#008000">CHttpFile</font>. The <font color="#008000">CFileFind</font> class and its derived classes help you find the file you want to 
open.</p>
<p><a href="index19.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index19.htm" target="text">Chapter 19</a>, &quot;Internet Programming with the WinInet Classes,&quot; works through an example client program using WinInet classes to establish an Internet session and retrieve information.</p>

<blockquote><p><img src="note.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/note.gif">
<p>Though e-mail is a standard Internet application, you'll notice that the WinInet classes do not have any e-mail functionality. That's because e-mail is handled by MAPI. There is no support for Usenet news either, in 
the WinInet classes or elsewhere.</p>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<h3><b>Using Internet Server API (ISAPI) Classes</b></h3>
<p>ISAPI is used to enhance and extend the capabilities of your HTTP (World Wide Web) server. ISAPI developers produce 
<i>extensions</i> and <i>filters</i>. Extensions are DLLs that are invoked by a user from a Web page in much the same way as CGI applications are invoked from a Web page. Filters are DLLs that run with the server and look at or change the data going to and 
from the server. For example, a filter might redirect requests for one file to a new location.</p>
<blockquote><p><img src="note.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/note.gif">
<p>In order for the ISAPI extensions and filters that you write to be useful, your Web pages must be kept on a server 
that is running as ISAPI-compliant server like the Microsoft IIS Server. You must have permission to install DLLs onto the server, and for an ISAPI filter, you must be able to change the Registry on the server. If your Web pages are kept on a machine 
administered by your Internet Service Provider (ISP), you will probably not be able to use ISAPI to bring more power to your Web pages. You may choose to move your pages to a dedicated server (a powerful Intel machine running Windows NT Server 4.0 and 
Microsoft IIS is a good combination) so that you can use ISAPI, but this will involve considerable expense. Make sure that you understand the constraints of your current Web server before embarking on a project with ISAPI.</p>
<p>One of the major 
advantages of ActiveX controls for the Internet (discussed in <a href="index21.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index21.htm" target="text">Chapter 21</a>, &quot;The Active Template Library,&#148; is that you do not need access to the server in order to implement them.</p>
<p><img 
src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<p>The five MFC ISAPI classes form a wrapper for the API to make it easier to use. They are:</p>
<ul>
<li> <font color="#008000">CHttpServer</font></pre>
<li> <font color="#008000">CHttpFilter</font></pre>
<li> <font 
color="#008000">CHttpServerContext</font></pre>
<li> <font color="#008000">CHttpFilterContext</font></pre>
<li> <font color="#008000">CHtmlStream</font></pre>
</ul>
<p>Your application will have a server or a filter class (or both) that inherit from <font 
color="#008000">CHttpServer</font> or <font color="#008000">CHttpFilter</font>. These are rather like the classes in a normal application that inherit from <font color="#008000">CWinApp</font>. There is only one instance of the class in each DLL, and each 
interaction of the server with a client is done through its own instance of the appropriate context class. (A DLL may contain both a server and a filter, but at most one of each.) <font color="#008000">CHtmlStream</font> is a helper class that describes a 
stream of HTML to be sent by a server to a client.</p>
<p>The ISAPI Extension Wizard is an AppWizard that simplifies creating extensions and filters. To use this wizard, choose <u>F</u>ile, <u>N</u>ew, as always, and then the Project tab. Scroll down the 
list on the left and select ISAPI Extension Wizard (as shown in Figure 18.5) and then fill in the project name and folder, and click OK.</p>
<a href="Tfigs05.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch18/Tfigs05.gif"><b>FIG. 18.5</b></a>
<p><i>The ISAPI Extension Wizard is another kind of 
AppWizard.</i></p>
<p>Creating a server extension is a one-step process. That step, which is also the first step for a filter, is shown in Figure 18.6. The names and descriptions for the filter and extension are based on the project name that you 
chose.</p>
<a href="Tfigs06.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch18/Tfigs06.gif"><b>FIG. 18.6</b></a>
<p><i>The first step in the ISAPI Extension Wizard process is to name the </i><i>components of the DLL that you are creating.</i></p>
<p>If you choose to create a filter, the Next button is 
enabled and you can move to the second step for filters, shown in Figure 18.7. This list of parameters gives you an idea of the power of an ISAPI filter. You can monitor all incoming and outgoing requests and raw data, authenticate users, log traffic, and 
more.</p>
<a href="Tfigs07.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch18/Tfigs07.gif"><b>FIG. 18.7</b></a>
<p><i>The second step in the ISAPI Extension Wizard process is to set </i><i>filter parameters.</i></p>
<p>AppWizard shows you a final confirmation screen before creating the files. When you 
create a server and a filter at the same time, 11 files are created for you, including source and headers for the class that inherits from <font color="#008000">CHttpServer</font> and the class that inherits from <font 
color="#008000">CHttpFilter</font>.</p>
<p>Writing a filter from this shell is quite simple. You have been provided with a stub function to react to each event for which notification was requested. For example, the filter class has a function called <font 
color="#008000">OnEndOfNetSession()</font>, which is called when a client's session with this server is ending. You add code to this function to log, monitor, or otherwise react to this event. When the filter is complete, you edit the Registry by hand so 
that the server will run your DLL.</p>
<p>To write an extension, add one or more functions to your DLL. Each function will be passed a <font color="#008000">CHttpContext</font> pointer, which can be used to gather information such as the user's IP address. 
If the function is invoked from an HTML form, additional parameters such as values of other fields on the form will also be passed to the function.</p>
<p>The details of what the function does depend on your application. If you are implementing an online 
ordering system, the functions involved will be lengthy and complex. Other extensions will be simpler.</p>
<p>When the function is complete, you place the DLL in the executable folder for the server&#151;usually the folder where CGI programs are 
kept&#151;and adjust your Web pages so that they include links to your DLL, like this:</p>
<pre><font color="#008000">Now you can &lt;A HREF=http://www.company.com/exec/orders.dll&gt;</font></pre>
<pre><font color="#008000">place an order&lt;/A&gt; 
online!</font></pre>
<p>For more information on ISAPI programming, be sure to read Que&#146;s <i>Special </i><i>Edition Using ISAPI</i>, included in its entirety on this book&#146;s CD. You will learn how ISAPI applications can make your Web site dynamic 
and interactive, learn how to write filters and extensions, and cover advanced topics including debugging ISAPI applications and writing multi-threaded applications.</p>
<h3><b>From Here...</b></h3>
<p>Adding the Internet to your applications is an 
exciting trend. It's going to make lots of work for programmers and create some powerful products that simplify the working life of anyone with an Internet connection. Just a year ago, writing Internet applications meant getting your fingernails dirty with 
sockets programming, memorizing TCP/IP ports, and reading RFCs. The new WinInet and ISAPI classes, as well as improvements to the old MAPI support, mean that today you can add amazing power to your application with just a few lines of code or by selecting 
a box on an AppWizard dialog box.</p>
<p>To learn more about using the APIs introduced in this chapter and building other specific kinds of applications refer to:</p>
<ul>
<li> <a href="index22.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index22.htm" target="text">Chapter 22</a>, &quot;Database 
Access,&quot; covers the basics of database manipulation.</p>
<li> <a href="index19.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index19.htm" target="text">Chapter 19</a>, &quot;Internet Programming with the WinInet Classes&quot; lets you work through an example program built with the WinInet classes.</p>

</ul>
<p><hr></p>
<center>
<p><font size=-2>
&copy; 1997, QUE Corporation, an imprint of Macmillan Publishing USA, a
Simon and Schuster Company.</font></p>
</center>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -