?? ch18.htm
字號(hào):
CMC_TYPE_INDIVIDUAL,
"SMTP:kate@gregcons.com",
CMC_ROLE_TO,
CMC_RECIP_LAST_ELEMENT,
NULL };
</PRE>
<P>The type, role, and flags use one of these predefined values:</P>
<P>
<H4>Listing 18.1  (Excerpt from \MSDev\Include\XCMC.H) Command Definitions</H4>
<PRE>/* NAME TYPES */
#define CMC_TYPE_UNKNOWN ((CMC_enum) 0)
#define CMC_TYPE_INDIVIDUAL ((CMC_enum) 1)
#define CMC_TYPE_GROUP ((CMC_enum) 2)
/* ROLES */
#define CMC_ROLE_TO ((CMC_enum) 0)
#define CMC_ROLE_CC ((CMC_enum) 1)
#define CMC_ROLE_BCC ((CMC_enum) 2)
#define CMC_ROLE_ORIGINATOR ((CMC_enum) 3)
#define CMC_ROLE_AUTHORIZING_USER ((CMC_enum) 4)
/* RECIPIENT FLAGS */
#define CMC_RECIP_IGNORE ((CMC_flags) 1)
#define CMC_RECIP_LIST_TRUNCATED ((CMC_flags) 2)
</PRE>
<PRE>#define CMC_RECIP_LAST_ELEMENT ((CMC_flags) 0x80000000)
</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 cmc_logon(),
cmc_send(), and cmc_logoff() to complete the process.</P>
<P><B>Extended MAPI  </B>Extended MAPI is based on COM, the 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, Chapter 13, "ActiveX Concepts."</P>
<P><B>Active Messaging  </B>If you understand Automation (described in
Chapter 16, "Building an Automation Server"), you will easily understand
Active Messaging. Your application must be an Automation client, however, and building
such a client is beyond the scope of this chapter. Various ways to use Active Messaging
are in Visual Basic programming and VBA scripts for programs such as 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 Send() method of a message object).</P>
<P>The objects used in Active Messaging include the following:</P>
<UL>
<LI>Session
<P>
<LI>Message
<P>
<LI>Recipient
<P>
<LI>Attachment
</UL>
<P>Active messaging is part of the Collaboration Data Objects (CDO) library. A detailed
reference of these objects, as well as their properties and methods, can be found
in MSDN under Platform SDK, Database and Messaging Services, Collaboration Data Objects,
CDO Library, and Reference. You'll find three articles on using Active Messaging,
and sample applications, under Technical Articles, Database and Messaging Services,
Microsoft Exchange Server.</P>
<P>
<H2><A NAME="Heading7"></A>Using the WinInet Classes</H2>
<P>MFC 4.2 introduced a number of new classes that eliminate the need to learn socket
programming when your applications require access to 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>
<UL>
<LI>CInternetSession
<P>
<LI>CInternetConnection
<P>
<LI>CInternetFile
<P>
<LI>HttpConnection
<P>
<LI>CHttpFile
<P>
<LI>CGopherFile
<P>
<LI>CFtpConnection
<P>
<LI>CGopherConnection
<P>
<LI>CFileFind
<P>
<LI>CFtpFileFind
<P>
<LI>CGopherFileFind
<P>
<LI>CGopherLocator
<P>
<LI>CInternetException
</UL>
<BLOCKQUOTE>
<P>
<HR>
<strong>TIP:</strong> 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.
<HR>
</BLOCKQUOTE>
<P>First, your program establishes a session by creating a CInternetSession. Then,
if you have a uniform resource locator (URL) to a Gopher, FTP, or Web (HTTP) resource,
you can call that session's OpenURL() function to retrieve the resource as a read-only
CInternetFile. Your application can read the file, using CStdioFile functions, and
manipulate that data in whatever way you need.</P>
<P><A HREF="javascript:popUp('18uvc04.gif')"><B>FIG. 18.4</B></A><B> </B><I>The WinInet
classes make writing Internet client programs easier.</I></P>
<P>If you don't have an URL or don't want to retrieve a read-only file, you proceed
differently after establishing the session. Make a connection with a specific protocol
by calling the session's GetFtpConnection(), GetGopherConnection(), or GetHttpConnection()
functions, which return the appropriate connection object. You then call the connection's
OpenFile() function. CFtpConnection::OpenFile() returns a CInternetFile; CGopherConnection::OpenFile()
returns a CGopherFile; and CHttpConnection::OpenFile() returns a CHttpFile. The CFileFind
class and its derived classes help you find the file you want to open.</P>
<P>Chapter 19, "Internet Programming with the WinInet Classes," works through
a sample client program using WinInet classes to establish an Internet session and
retrieve information.</P>
<BLOCKQUOTE>
<P>
<HR>
<strong>NOTE:</strong> Though email is a standard Internet application, you'll notice that
the WinInet classes don't have any email functionality. That's because email is handled
by MAPI. There is no support for Usenet news either, in the WinInet classes or elsewhere.
<HR>
</BLOCKQUOTE>
<H2><A NAME="Heading8"></A>Using Internet Server API (ISAPI) Classes</H2>
<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 invoked by a user from a Web page in much the same way as CGI (common gateway
interface) applications are invoked from a Web page. Filters are DLLs that run with
the server and examine 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>
<HR>
<strong>NOTE:</strong> For the ISAPI extensions and filters that you write to be useful,
your Web pages must be kept on a server that is running an ISAPI-compliant server
such as 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.<BR>
</P>
<P>One of the major advantages of ActiveX controls for the Internet (discussed in
Chapter 20, "Building an Internet ActiveX Control") is that you don't need
access to the server in order to implement them. n
<HR>
</BLOCKQUOTE>
<P>The five MFC ISAPI classes form a wrapper for the API to make it easier to use:</P>
<UL>
<LI>CHttpServer
<P>
<LI>CHttpFilter
<P>
<LI>CHttpServerContext
<P>
<LI>CHttpFilterContext
<P>
<LI>CHtmlStream
</UL>
<P>Your application will have a server or a filter class (or both) that inherits
from CHttpServer or CHttpFilter. These are rather like the classes in a normal application
that inherit from CWinApp. There is only one instance of the class in each DLL, and
each interaction of the server with a client takes place 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.) CHtmlStream 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 File, New (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). Fill in the project name and folder, and click OK.</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>
<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>
<P><A HREF="javascript:popUp('18uvc05.gif')"><B>FIG. 18.5</B></A><B> </B><I>The ISAPI
Extension Wizard is another kind of AppWizard.</I></P>
<P><A HREF="javascript:popUp('18uvc06.gif')"><B>FIG. 18.6</B></A><B> </B><I>The first
step in the ISAPI Extension Wizard process is to name the components of the DLL that
you are creating.</I></P>
<P><A HREF="javascript:popUp('18uvc07.gif')"><B>FIG. 18.7</B></A><B> </B><I>The second
step in the ISAPI Extension Wizard process is to set filter parameters.</I></P>
<P>AppWizard shows you a final confirmation screen, like the one in Figure 18.8,
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 CHttpServer and the class that inherits from CHttpFilter.</P>
<P><A HREF="javascript:popUp('18uvc08.gif')"><B>FIG. 18.8</B></A><B> </B><I>The ISAPI
Extension Wizard process summarizes the files that will be created.</I></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 OnEndOfNetSession(), 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 CHttpContext 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, place the DLL in the executable folder for the
server--usually the folder where CGI programs are kept--and adjust your Web pages
so that they include links to your DLL, like this:</P>
<P>
<PRE>Now you can <A HREF=http://www.company.com/exec/orders.dll>
place an order</A> online!
</PRE>
<P>For more information on ISAPI programming, be sure to read Que's <I>Special Edition
Using ISAPI</I>. You will discover 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 multithreaded applications.</P>
<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. l</P>
<H1></H1>
<CENTER>
<P>
<HR>
<A HREF="../ch17/ch17.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch19/ch19.htm"><IMG
SRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR>
</P>
<P>© <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. All
rights reserved.
</CENTER>
</BODY>
</HTML>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -