Microsoft KB Archive/260216

= How to use the Outlook object model in an Exchange Client extension =

Article ID: 260216

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Messaging Application Programming Interface
 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Outlook 2002 Standard Edition
 * Microsoft Outlook 97 Standard Edition
 * Microsoft Outlook 98 Standard Edition
 * Microsoft Office Outlook 2003

-



This article was previously published under Q260216



SUMMARY
This article demonstrates how to access the Outlook Object Model from within an Exchange Client Extension. This is useful because many operations on e-mail messages and folders can only be performed with the Outlook Object Model.



MORE INFORMATION
To access the Outlook Object Model from within an extension, you can use the IOutlookExtCallback interface which is provided by Microsoft for this purpose. To use this interface, follow these steps:  Create a simple DLL project by following steps 1 through 8 in the following article in the Microsoft Knowledge Base:

285999 How to build a minimal Exchange client extension by using Visual C++

Note Before you build the DLL and add the registry values (steps 9 through 13 in Q285999), complete the remainder of the steps in this article.  Add to the project a header file, save the file in the project folder with a name such as &quot;OutlookInterface.h&quot;, and paste the following code in the body of the header file:
 * 1) pragma once


 * 1) if defined(WIN32) && !defined(MAC)

typedef interface IOutlookExtCallback IOutlookExtCallback;
 * 1) ifndef __IOutlookExtCallback_FWD_DEFINED__
 * 2) define __IOutlookExtCallback_FWD_DEFINED__
 * 1) endif   /* __IOutlookExtCallback_FWD_DEFINED__ */

// Outlook defines this interface as an alternate to IExchExtCallback.
 * 1) ifndef __IOutlookExtCallback_INTERFACE_DEFINED__
 * 2) define __IOutlookExtCallback_INTERFACE_DEFINED__

EXTERN_C const IID IID_IOutlookExtCallback;

interface DECLSPEC_UUID(&quot;0006720D-0000-0000-C000-000000000046&quot;) IOutlookExtCallback : public IUnknown {   public: virtual HRESULT STDMETHODCALLTYPE GetObject(            /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk) = 0; virtual HRESULT STDMETHODCALLTYPE GetOfficeCharacter(            /* [out] */ void __RPC_FAR *__RPC_FAR *ppmsotfc) = 0; };

DEFINE_GUID(IID_IOutlookExtCallback,   0x0006720d,    0x0000,    0x0000,    0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);


 * 1) endif   /* __IOutlookExtCallback_INTERFACE_DEFINED__ */

 To the main project .cpp file, add a #include statement for the header file you created in step 2; for example: #include &quot;OutlookInterface.h&quot;   After the #include statements, add the following #import statements to define the path to the Outlook library files, adjusting the paths as needed: //Path to Outlook object model files. //For Outlook 2000, use the following lines. #import &quot;D:\\Office\\Office\\mso9.dll&quot; no_namespace, named_guids, rename(&quot;DocumentProperties&quot;, &quot;DocProps&quot; ) #import &quot;D:\\Office\\Office\\msoutl9.olb&quot; no_namespace exclude(&quot;_IRecipientControl&quot;, &quot;_DRecipientControl&quot;)
 * 1) endif // defined(WIN32) && !defined(MAC) 

//For Outlook 2002, comment the lines above and uncomment the next 2 lines. // #import &quot;E:\program files\microsoft office\office10\mso.dll&quot; no_namespace, named_guids, rename(&quot;DocumentProperties&quot;, &quot;DocProps&quot; ) // #import &quot;E:\\Program Files\\Microsoft Office\\Office10\\msoutl.olb&quot; no_namespace exclude(&quot;_IRecipientControl&quot;, &quot;_DRecipientControl&quot;)   After the external declaration for the ExchEntryPoint function, add a prototype statement for the GetOutlookVersion function: void GetOutlookVersion(IExchExtCallback *pmecb);   In the Install function, paste the following code before the Return statement to call the GetOutlookVersion function: //Call function to display Outlook version. GetOutlookVersion(pmecb); </li>  At the end of the .cpp file, insert the following code to define the GetOutlookVersion function: void GetOutlookVersion(IExchExtCallback *pmecb) {  HRESULT hRes; _ApplicationPtr pOutlookApp; LPDISPATCH lpMyDispatch; IOutlookExtCallback *pOutlook = NULL; hRes = pmecb->QueryInterface(IID_IOutlookExtCallback,(void **) &pOutlook);

//If we are not running Outlook, pOutlook will be null. if (pOutlook) {     IUnknown *pUnk = NULL; pOutlook->GetObject(&pUnk);

if (pUnk != NULL) {        hRes = pUnk->QueryInterface(IID_IDispatch, (void **) &lpMyDispatch); pUnk->Release; }     if (lpMyDispatch) {        pOutlookApp = lpMyDispatch; if (pOutlookApp) {       _bstr_t szOLVersion = &quot;Outlook Version is: &quot; + pOutlookApp->Version; MessageBox(NULL, (char*)szOLVersion, &quot;Outlook Version&quot;, MB_OK); }        }      }   } </li> Follow steps 9 through 13 in Q285999 to finish building the extension DLL, add the required registry keys, and so on.</li></ol>

<div class="references_section">