P1: 50
Mayfield WL040/Bidgoli-Vol III-Ch-52 June 23, 2003 16:35 Char Count= 0
644 VISUALC++ (MICROSOFT)system. Kruglinski, Shepherd, and Wingo (1998) list sev-
eral specific advantages of WinInet over WinSock:File caching,
Support for proxy servers,
An easier API,
Security via authentication,
Buffered I/O capabilities, and
Better support functions.Does this mean that WinInet is a better alternative to
WinSock? No. WinInet is designed specifically for writ-
ing FTP, Gopher, and HTTP client programs; there is no
support for writing server software nor for writing In-
ternet applications that fall outside the three categories
listed above. The general sequence of events for writing a
WinInet client application is as follows:Create an instance of the MFC classCInternetSession;
Open a connection from the CInternetSessionin-
stance to a URL (Universal Resource Locator) using the
methodOpenURL; if the argument toOpenURLis of the
form “ftp://...,” “gopher://...,” or “http://...” the method
will return aCInternetFilepointer, aCGopherFile
pointer, or aCHttpFilepointer, respectively.
Use the appropriate file pointer to call the methodsRead,
Write, ReadString,andWriteStringto commu-
nicate with the server.A WinInet Example
Listing 5 presents the WinInet code segment from an MFC
console application that reads and displays the HTML
code that makes up the Microsoft main Web page. The file
containing the code shown in Listing 5 also must contain
the preprocessor statement#include <afxinet.h>.Listing 5:WinInet console application code segment.
(1) CInternetSession session;
(2) CHttpFile *pFile;
(3) CString buffer;
(4) DWORD dwStatus;
(5)
(6) // Open the URL for Microsoft's main
page.
(7) pFile =
(8) (CHttpFile*)session.OpenURL(
"http://microsoft.com");
(9)
(10) // Make sure the open was successful.
(11) pFile->QueryInfoStatusCode(dwStatus);
(12) if ((dwStatus < 200) || (dwStatus >
299)) {
(13) // The URL could not be opened.
(14) return false;
(15) }
(16)
(17) // Get and display the HTML code from
the Web page.(18) while (pFile->ReadString(buffer))
(19) cout << (const char*)buffer << endl;
(20)
(21) // Close the HTTP file.
(22) pFile->Close();
(23) // Close the connection.
(24) session.Close();OLE, ACTIVEX, AND COM
OLE
OLE (Object Linking and Embedding) was one of
Microsoft’s first attempts to create a common, cross-
application API format. OLE makes it possible to share
data, objects, and components among different appli-
cations. One of the first and most obvious applications
of OLE was the ability to drag and drop data and ob-
jects from one application (for example, Microsoft Ex-
cel) into another application (for example, Microsoft
Word).ActiveX
ActiveX is the successor to OLE. (More specifically, Ac-
tiveX controls are the successor to OLE controls.) Kruglin-
ski et al. (1998) say that one can view ActiveX “as some-
thing that was created when the ‘old’ OLE collided with
the Internet.” Visual C++ comes ready with numerous
ActiveX controls available. For example, a month calen-
dar control is available on the toolbar of the IDE dialog
editor; Figure 8 depicts the use of this control in a simple
application. For those who want to write their own cus-
tom ActiveX controls, Visual C++ includes the ATL (Active
Template Library).COM
COM (Component Object Model) is the underlying archi-
tecture used in ActiveX technology. The main advantage of
COM (and other component technologies) is that of com-
ponent reuse. Rogerson (1997) points out that COM com-
ponents can be used across many procedural and object-
oriented languages, and they can be updated or relocated
(locally or on a network) with little or no effect on the
applications that use the components.ActiveX and Web Programming
Numerous ActiveX controls are available to promote the
development of Visual C++ Web-aware applications. A
good example is the Web browser control provided by Mi-
crosoft; using it, one can write Web browser applications
or applications that have Web browsers embedded within
them. Because this control is based on the technology
used in Microsoft Internet Explorer, one can use it to
make applications have the look and feel of Internet Ex-
plorer. From the other side of the browser wars comes an-
other Web browser control provided by the Mozilla Group
(2000). This control is based on the Gecko layout engine,
which is the same technology used in the Mozilla and
Netscape Web browsers.