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

📄 ch12.htm

📁 MAPI__SAPI__TAPI
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  {<br>
  &nbsp;public:<br>
  &nbsp;&nbsp;&nbsp;&nbsp;CDGExtMsgEvents (LPUNKNOWN pParentInterface) {<br>
  &nbsp;&nbsp;&nbsp;&nbsp;m_pExchExt = pParentInterface;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;m_cRef = 0;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;m_bInSubmitState = FALSE;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;};<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;inline STDMETHODIMP_(ULONG) AddRef() { ++m_cRef; return m_cRef; };<br>
  &nbsp;&nbsp;&nbsp;&nbsp;inline STDMETHODIMP_(ULONG) Release() <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ 
  ULONG ulCount = -m_cRef;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if 
  (!ulCount) { delete this; }<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 
  ulCount;};<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP OnRead(LPEXchEXTCALLBACK lpeecb);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP OnReadComplete(LPEXchEXTCALLBACK lpeecb, ULONG 
  ulFlags);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP OnWrite(LPEXchEXTCALLBACK lpeecb);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP OnWriteComplete(LPEXchEXTCALLBACK lpeecb, ULONG 
  ulFlags);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP OnSubmit(LPEXchEXTCALLBACK lpeecb);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP_ (VOID)OnSubmitComplete(LPEXchEXTCALLBACK lpeecb, 
  ULONG ulFlags);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP OnCheckNames(LPEXchEXTCALLBACK lpeecb);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;STDMETHODIMP OnCheckNamesComplete(LPEXchEXTCALLBACK lpeecb, ULONG 
  ulFlags);<br>
  <br>
  <br>
  &nbsp;private:<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ULONG&nbsp;&nbsp;&nbsp;m_cRef;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;HRESULT m_hrOnReadComplete;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;BOOL&nbsp;&nbsp;&nbsp;&nbsp;m_bInSubmitState; <br>
  &nbsp;&nbsp;&nbsp;&nbsp;LPUNKNOWN m_pExchExt;<br>
  <br>
  };</font></tt> </p>
</blockquote>

<hr>

<p>This is all there is to the <tt><font FACE="Courier">CDGEXT32.H</font></tt> header 
file. Next, you'll review the code for the main extension DLL. </p>

<h3><a NAME="CodingtheMainDLLRoutines"><b>Coding the Main DLL Routines</b></a></h3>

<p>The <tt><font FACE="Courier">CDGEXT32.CPP</font></tt> file contains the main body of 
code for the extension. The code file can be divided into five parts: 

<ul>
  <li><font COLOR="#000000">Initialization and main entry code</font> </li>
  <li><font COLOR="#000000">Code for the high-level </font><tt><font FACE="Courier">IExchExt</font></tt> 
    object </li>
  <li><font COLOR="#000000">Code for the </font><tt><font FACE="Courier">IExchExtPropertySheets</font></tt> 
    object </li>
  <li><font COLOR="#000000">Code for the </font><tt><font FACE="Courier">IExchExtMessageEvents</font></tt> 
    object </li>
  <li><font COLOR="#000000">Helper code for local routines</font> </li>
</ul>

<p>Listing 12.5 shows the initialization and main entry code for <tt><font FACE="Courier">CDGEXT32.CPP</font></tt>. 
This code handles some basic housekeeping and then establishes the DLL entry point (<tt><font
FACE="Courier">DLLMain</font></tt>) and the callback address for the <tt><font
FACE="Courier">IExchExt</font></tt> object (<tt><font FACE="Courier">ExchEntryPoint</font></tt>). 
</p>

<hr>

<blockquote>
  <b><p>Listing 12.5. The initialization and main entry code for <tt><font FACE="Courier">CDGEXT32.CPP</font></tt>. 
  <br>
  </b></p>
</blockquote>

<blockquote>
  <tt><font FACE="Courier"><p>//&nbsp;================================================================== 
  <br>
  //&nbsp;CDGEXT32.CPP<br>
  //&nbsp;================================================================== <br>
  <br>
  //<br>
  //&nbsp;module-level defines<br>
  //<br>
  #define INITGUID<br>
  #define USES_IID_IExchExt<br>
  #define USES_IID_IExchExtAdvancedCriteria<br>
  #define USES_IID_IExchExtAttachedFileEvents<br>
  #define USES_IID_IExchExtCommands<br>
  #define USES_IID_IExchExtMessageEvents<br>
  #define USES_IID_IExchExtPropertySheets<br>
  #define USES_IID_IExchExtSessionEvents<br>
  #define USES_IID_IExchExtUserEvents<br>
  #define USES_IID_IMessage<br>
  #define USES_PS_MAPI<br>
  <br>
  //<br>
  //&nbsp;include files<br>
  //<br>
  #include &quot;CDGEXT32.H&quot;<br>
  #include &lt;INITGUID.H&gt;<br>
  #include &lt;MAPIGUID.H&gt;<br>
  <br>
  //<br>
  //&nbsp;local declarations<br>
  //<br>
  MAPINAMEID NamedID[1]; // for new property<br>
  BOOL bSignatureOn = TRUE; // assume it's on<br>
  static HINSTAncE ghInstDLL = NULL;&nbsp;&nbsp;// DLL handle<br>
  <br>
  <br>
  //&nbsp;---------------------------------------------------------------- <br>
  //&nbsp;Main Body of routines<br>
  //<br>
  //&nbsp;These two routines are the initial entry point for the DLL and<br>
  //&nbsp;the code that registers the extension DLL.<br>
  //&nbsp;---------------------------------------------------------------- <br>
  <br>
  //<br>
  //&nbsp;to start things off as a DLL<br>
  //<br>
  BOOL WINAPI DllMain(<br>
  &nbsp;&nbsp;&nbsp;&nbsp;HINSTAncE&nbsp;&nbsp;hinstDLL,<br>
  &nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;&nbsp;fdwReason,<br>
  &nbsp;&nbsp;&nbsp;&nbsp;LPVOID&nbsp;&nbsp;lpvReserved)<br>
  {<br>
  &nbsp;if (DLL_PROCESS_ATTAch == fdwReason)<br>
  &nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ghInstDLL = hinstDLL;<br>
  <br>
  &nbsp;}<br>
  &nbsp;return TRUE;<br>
  }<br>
  <br>
  //<br>
  //&nbsp;register the extension<br>
  //<br>
  LPEXchEXT CALLBACK ExchEntryPoint(void)<br>
  {<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new CDGExt;<br>
  }</font></tt> </p>
</blockquote>

<hr>

<p>Next is the code for the methods and properties of the <tt><font FACE="Courier">IExchExt</font></tt> 
object. Along with the initial object constructor code, three methods must be coded: 

<ul>
  <li><font COLOR="#000000">The </font><tt><font FACE="Courier">QueryInterface</font></tt> 
    method </li>
  <li><font COLOR="#000000">The </font><tt><font FACE="Courier">Install</font></tt> method </li>
  <li><font COLOR="#000000">The </font><tt><font FACE="Courier">Release</font></tt> method </li>
</ul>

<p>Listing 12.6 shows the code for the <tt><font FACE="Courier">IExchExt</font></tt> 
object. </p>

<hr>

<blockquote>
  <b><p>Listing 12.6. Code for the <tt><font FACE="Courier">IExchExt</font></tt> interface.<br>
  </b></p>
</blockquote>

<blockquote>
  <tt><font FACE="Courier"><p>//&nbsp;------------------------------------------ <br>
  //&nbsp;Handle the creation of the CDGExt object<br>
  //&nbsp;------------------------------------------<br>
  //<br>
  //&nbsp;These routines establish the initial<br>
  //&nbsp;extension interface.<br>
  //<br>
  //&nbsp;CDGExt::CDGExt() - constructor<br>
  //&nbsp;CDGExt::Release() - frees up resources<br>
  //&nbsp;CDGExt::QueryInterface() - main entry<br>
  //&nbsp;CDGExt::Install() - installs extensions<br>
  //&nbsp;--------------------------------------------<br>
  <br>
  //<br>
  //&nbsp;constructor for the propertysheet and message event extension <br>
  //<br>
  CDGExt::CDGExt()<br>
  {<br>
  &nbsp;&nbsp;m_cRef = 1;<br>
  &nbsp;&nbsp;m_pExchExtPropertySheets = new CDGExtPropSheets(this); <br>
  &nbsp;&nbsp;m_pExchExtMessageEvents = new CDGExtMsgEvents(this); <br>
  <br>
  };<br>
  <br>
  <br>
  //<br>
  //&nbsp;frees up resources when done<br>
  //<br>
  STDMETHODIMP_(ULONG) CDGExt::Release()<br>
  {<br>
  &nbsp;ULONG ulCount = -m_cRef;<br>
  <br>
  &nbsp;if (!ulCount)<br>
  &nbsp;{<br>
  &nbsp;&nbsp;delete this;<br>
  &nbsp;}<br>
  <br>
  return ulCount;<br>
  <br>
  }<br>
  <br>
  //<br>
  //&nbsp;initial interface query<br>
  //&nbsp;for both propertysheets and message events<br>
  //<br>
  STDMETHODIMP CDGExt::QueryInterface(REFIID riid, LPVOID FAR * ppvObj)<br>
  {<br>
  &nbsp;&nbsp;&nbsp;&nbsp;HRESULT hResult = S_OK;<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;*ppvObj = NULL;<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;if (( IID_IUnknown == riid) || ( IID_IExchExt == riid) )<br>
  &nbsp;&nbsp;&nbsp;&nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*ppvObj = (LPUNKNOWN)this; <br>
  &nbsp;&nbsp;&nbsp;&nbsp;}<br>
  &nbsp;&nbsp;&nbsp;&nbsp;else if (IID_IExchExtPropertySheets == riid) // for property 
  sheets?<br>
  &nbsp;&nbsp;&nbsp;&nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// ignore send/read contexts (for property sheet)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( (m_context == 
  EECONTEXT_SENDNOTEMESSAGE)&nbsp;&nbsp;&nbsp;||<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(m_context 
  == EECONTEXT_SENDPOSTMESSAGE)&nbsp;&nbsp;&nbsp;||<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(m_context 
  == EECONTEXT_SENDRESENDMESSAGE)&nbsp;||<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(m_context 
  == EECONTEXT_READNOTEMESSAGE)&nbsp;&nbsp;&nbsp;||<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(m_context 
  == EECONTEXT_READPOSTMESSAGE)&nbsp;&nbsp;&nbsp;||<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(m_context 
  == EECONTEXT_READREPORTMESSAGE)&nbsp;)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 
  E_NOINTERFACE;<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;otherwise return the interface <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*ppvObj = (LPUNKNOWN) 
  m_pExchExtPropertySheets;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;}<br>
  &nbsp;&nbsp;&nbsp;&nbsp;else if (IID_IExchExtMessageEvents == riid) // for message events?<br>
  &nbsp;&nbsp;&nbsp;&nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*ppvObj = (LPUNKNOWN) 
  m_pExchExtMessageEvents;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;}<br>
  &nbsp;&nbsp;&nbsp;&nbsp;else<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hResult = E_NOINTERFACE; <br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;if (NULL != *ppvObj)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((LPUNKNOWN)*ppvObj)-&gt;AddRef(); <br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;return hResult;<br>
  }<br>
  <br>
  <br>
  //<br>
  //&nbsp;actually installs the extension<br>
  //<br>
  STDMETHODIMP CDGExt::Install(LPEXchEXTCALLBACK peecb, ULONG eecontext, ULONG <font
  FACE="ZAPFDINGBATS">&Acirc;</font>ulFlags)<br>
  {<br>
  &nbsp;&nbsp;&nbsp;&nbsp;ULONG ulBuildVersion;<br>
  HRESULT hr;<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;m_context = eecontext;<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;compare versions<br>
  &nbsp;&nbsp;&nbsp;&nbsp;peecb-&gt;GetVersion(&amp;ulBuildVersion, EECBGV_GETBUILDVERSION);<br>
  &nbsp;&nbsp;&nbsp;&nbsp;if (EECBGV_BUILDVERSION_MAJOR != (ulBuildVersion &amp;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EECBGV_BUILDVERSION_MAJOR_MA 
  SK)) <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return S_FALSE;&nbsp;&nbsp;// oops!<br>
  <br>
  &nbsp;&nbsp;&nbsp;&nbsp;switch (eecontext)<br>
  &nbsp;&nbsp;&nbsp;&nbsp;{<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EECONTEXT_PROPERTYSHEETS:<br>
  &nbsp;&nbsp;&nbsp;&n

⌨️ 快捷键说明

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