📄 ch12.htm
字号:
<p align="center"><b>Table 12.9. The COM <tt><font FACE="Courier">InterfaceMap</font></tt>
parameter positions.</b> </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><i>Parameter Position</i></td>
<td WIDTH="272"><i>Interface</i> </td>
</tr>
<tr>
<td WIDTH="143"><p align="center">1</td>
<td WIDTH="272"><tt><font FACE="Courier">IExchExtCommands</font></tt> </td>
</tr>
<tr>
<td WIDTH="143"><p align="center">2 </td>
<td WIDTH="272"><tt><font FACE="Courier">IExchExtUserEvents</font></tt> </td>
</tr>
<tr>
<td WIDTH="143"><p align="center">3</td>
<td WIDTH="272"><tt><font FACE="Courier">IExchExtSessionEvents</font></tt> </td>
</tr>
<tr>
<td WIDTH="143"><p align="center">4</td>
<td WIDTH="272"><tt><font FACE="Courier">IExchExtMessageEvents</font></tt> </td>
</tr>
<tr>
<td WIDTH="143"><p align="center">5</td>
<td WIDTH="272"><tt><font FACE="Courier">IExchExtAttachedFileEvents</font></tt> </td>
</tr>
<tr>
<td WIDTH="143"><p align="center">6</td>
<td WIDTH="272"><tt><font FACE="Courier">IExchExtPropertySheets</font></tt> </td>
</tr>
<tr>
<td WIDTH="143"><p align="center">7</td>
<td WIDTH="272"><tt><font FACE="Courier">IExchExtAdvancedCriteria</font></tt> </td>
</tr>
</table>
</center></div>
<p>For example, if your DLL extension used the property sheet and message interfaces,
you'd create an <tt><font FACE="Courier">InterfaceMap</font></tt> parameter that looks
like the following: </p>
<p><tt><font FACE="Courier">"0001010"</font></tt> </p>
<p>Later in this chapter, you'll make a registry entry to match the Message Signing
Extension example described in this chapter. </p>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Warning</b></td>
</tr>
<tr>
<td><blockquote>
<p>It is acceptable to leave out trailing bits in the interface and context map parameters
and allow Microsoft Exchange to assume these missing entries are zero ("0").
However, it is not recommended. It is much better to construct a complete string, even if
most of them are set to zero.</p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<p>Now that you know the theory behind creating Windows Messaging client extensions and
how to register them for use, you're ready to build the sample project. </p>
<h2><a NAME="CreatingtheMessageSigningExtension"><b><font SIZE="5" COLOR="#FF0000">Creating
the Message Signing Extension</font></b></a></h2>
<p>The sample Windows Messaging client extension described in this chapter creates a
checksum of each message body and stores that value before it is sent to the recipient.
The same extension also checks the stored value against the computed checksum each time
the user attempts to read a message. If, upon reading the message, the stored checksum is
not equal to the computed checksum, it is likely that the message has been altered in some
way since it was submitted for delivery by the original author. In this way, you can
implement a rather simple message signature process that will give a high degree of
confidence that the messages users receive have not been tampered with before they arrive
at their destination. </p>
<p>There are four main steps to creating the Message Signing extension DLL:
<ul>
<li><i>Building the initial header file</i>-This file will contain global declarations along
with prototypes for the Microsoft Exchange class objects and their associated methods. </li>
<li><i>Coding the main DLL routines</i>-These are the actual routines that register the DLL
for callbacks to the COM interfaces and establish code behavior for the necessary COM
interface methods. </li>
<li><i>Laying out the Property Sheet dialog box</i>-This dialog box will be registered and
accessed from the <tt><font FACE="Courier">Tools | Options</font></tt> menu of the Windows
Messaging client. </li>
<li><i>Coding the Property Sheet dialog box events</i>-This is the code to handle user
interaction with the registered property page. </li>
</ul>
<div align="center"><center>
<table BORDERCOLOR="#000000" BORDER="1" WIDTH="80%">
<tr>
<td><b>Note</b></td>
</tr>
<tr>
<td><blockquote>
<p>If you own a copy of Microsoft Visual C++, you can load the <tt><font FACE="Courier">CDGEXT32</font></tt>
project found on the CD-ROM that ships with this book. If you do not have a copy of C++,
you can still load the source code files and review them as you read along in this
chapter. </p>
</blockquote>
</td>
</tr>
</table>
</center></div>
<h3><a NAME="BuildingtheInitialHeaderFile"><b>Building the Initial Header File</b></a></h3>
<p>The initial header file (<tt><font FACE="Courier">CDGEXT32.H</font></tt>) contains
basic defines, includes, and global declarations. It also contains the prototypes for the
Microsoft Exchange class objects and their associated methods. Listing 12.1 shows the
first part of the <tt><font FACE="Courier">CDGEXT32.H</font></tt> file. </p>
<hr>
<blockquote>
<b><p>Listing 12.1. The first half of the <tt><font FACE="Courier">CDGEXT32.H</font></tt>
header file.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>// ========================================================================
<br>
// CDGEXT32.H<br>
// ======================================================================== <br>
#ifndef __CDGEXT32_H__<br>
#define __CDGEXT32_H__<br>
<br>
//<br>
// include files<br>
//<br>
#include <WINDOWS.H><br>
#include <COMMCTRL.H><br>
#include <MAPIX.H><br>
#include <MAPIUTIL.H><br>
#include <MAPIFORM.H><br>
#include <EXchEXT.H><br>
<br>
#include "RESOURCE.H"<br>
<br>
//<br>
// function prototypes<br>
//<br>
extern "C"<br>
{<br>
LPEXchEXT CALLBACK ExchEntryPoint(void);<br>
}<br>
<br>
void ErrMsgBox(HWND hWnd, HRESULT hr, PSTR szFunction, LPSTR
szMessage);<br>
HRESULT CheckMsgSignature(LPMESSAGE pMsg, ULONG *pulCheckSum); <br>
BOOL CALLBACK MsgSigningDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM <font
FACE="ZAPFDINGBATS">Â</font>lParam);<br>
<br>
// global declarations<br>
extern BOOL bSignatureOn;<br>
<br>
//<br>
// class declarations<br>
//<br>
class CDGExt;<br>
class CDGExtPropSheets;<br>
class CDGExtMsgEvents;</font></tt> </p>
</blockquote>
<hr>
<p>The code in Listing 12.1 first lists all the include files needed for the project
(these are part of the MAPI SDK that can be found on MSDN Professional Level CD-ROMs and
above). Next is the declaration of the initial entry point for the Microsoft Exchange DLL
extension, along with three custom functions used in the project, along with a single
variable declaration. Finally, the three COM objects that will be used in the project are
declared. </p>
<p>Listing 12.2 shows the <tt><font FACE="Courier">CDGEXT32.H</font></tt> code that
defines the methods and properties of the high-level <tt><font FACE="Courier">IExchExt</font></tt>
interface object. This object will be used to install the extension and register the DLL
for property sheet and message events. </p>
<hr>
<blockquote>
<b><p>Listing 12.2. Defining the <tt><font FACE="Courier">IExchExt</font></tt> interface
object.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>//<br>
// overall exchange extension class<br>
//<br>
class CDGExt : public IExchExt<br>
{<br>
<br>
public:<br>
CDGExt();<br>
STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);<br>
inline STDMETHODIMP_(ULONG) AddRef() { ++m_cRef; return m_cRef; };<br>
STDMETHODIMP_(ULONG) Release();<br>
STDMETHODIMP Install (LPEXchEXTCALLBACK pmecb, ULONG mecontext,
ULONG ulFlags);<br>
<br>
private:<br>
ULONG m_cRef;<br>
UINT m_context;<br>
CDGExtPropSheets * m_pExchExtPropertySheets; <br>
CDGExtMsgEvents * m_pExchExtMessageEvents; <br>
<br>
};</font></tt> </p>
</blockquote>
<hr>
<p>Next, Listing 12.3 shows the definition of the <tt><font FACE="Courier">Property Sheets</font></tt>
object. </p>
<hr>
<blockquote>
<b><p>Listing 12.3. Defining the <tt><font FACE="Courier">IExchExtPropertySheets</font></tt>
COM interface.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>//<br>
// property sheet extension class<br>
//<br>
class CDGExtPropSheets : public IExchExtPropertySheets<br>
{<br>
public:<br>
CDGExtPropSheets (LPUNKNOWN pParentInterface) {<br>
m_pExchExt = pParentInterface;<br>
m_cRef = 0;<br>
};<br>
<br>
<br>
STDMETHODIMP QueryInterface(REFIID riid, LPVOID *
ppvObj);<br>
inline STDMETHODIMP_(ULONG) AddRef() { ++m_cRef; return m_cRef; };<br>
inline STDMETHODIMP_(ULONG) Release() <br>
{ ULONG ulCount = -m_cRef;<br>
if (!ulCount) {
delete this; }<br>
return ulCount;};<br>
<br>
STDMETHODIMP_ (ULONG) GetMaxPageCount(ULONG ulFlags);<br>
STDMETHODIMP GetPages(LPEXchEXTCALLBACK peecb, ULONG ulFlags, <font
FACE="ZAPFDINGBATS">Â</font>LPPROPSHEETPAGE ppsp, ULONG FAR * pcpsp);<br>
STDMETHODIMP_ (VOID) FreePages(LPPROPSHEETPAGE ppsp, ULONG
ulFlags, ULONG <font FACE="ZAPFDINGBATS">Â</font>cpsp);<br>
<br>
private:<br>
ULONG m_cRef;<br>
LPUNKNOWN m_pExchExt;<br>
};</font></tt> </p>
</blockquote>
<hr>
<p>Finally, Listing 12.4 shows the code that defines the <tt><font FACE="Courier">Message
Event</font></tt> COM interface. </p>
<hr>
<blockquote>
<b><p>Listing 12.4. Defining the <tt><font FACE="Courier">IExchExtMessageEvents</font></tt>
COM interface.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>//<br>
// message event extension class<br>
//<br>
class CDGExtMsgEvents : public IExchExtMessageEvents<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -