468,504 Members | 2,001 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,504 developers. It's quick & easy.

Connect to outlook from C++

Outlook 2007 uses the MS Word editor for composing/viewing emails. I'm trying to get a handle to the Word object within outlook and have most of the code. There's one line that's giving me an error and I'm not sure how to get around it. The compiler refuses to compile because of the line which says QueryInterface. The error is "error C2787: 'MSWord::_Document' : no GUID has been associated with this object". I've been breaking my head over this for hours. Anyone know how to fix this?
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include "./MSWord/msword8.h"
  3.  
  4. // Define this according to the Outlook Object
  5. // Model version you are compiling under
  6. #define OUTL12    // Outlook 2007
  7.  
  8. #pragma warning(disable:4146)
  9.  
  10. #if defined(OUTL12) // Outlook 2007
  11.     #import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll" \
  12.         no_namespace
  13.     #import "C:\Program Files\Microsoft Office\OFFICE12\msoutl.olb" \
  14.         rename_namespace("Outlook")
  15. #endif // OUTL12
  16.  
  17. #pragma warning(default:4146)
  18.  
  19. void GetOutlookWordEditor (MSWord::_Application *pWordApp)
  20. {
  21.     CLSID clsid;
  22.     LPUNKNOWN pUnk;
  23.     CLSIDFromProgID(L"Outlook.Application", &clsid);
  24.     HRESULT hr = ::GetActiveObject(clsid, NULL, &pUnk);
  25.     if (SUCCEEDED(hr))
  26.     {
  27.         // Get IDispatch
  28.         IDispatch *pDispApp;
  29.         HRESULT hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDispApp);
  30.  
  31.         if (FAILED(hr))
  32.         {
  33.             return;
  34.         }
  35.  
  36.         pUnk->Release();
  37.  
  38.         Outlook::_ApplicationPtr outlookApp(pDispApp);
  39.  
  40.         if(outlookApp->ActiveInspector()!=NULL)
  41.         {
  42.             Outlook::_InspectorPtr pInsp(outlookApp->ActiveInspector());
  43.             if(pInsp!=NULL)
  44.             {
  45.                 IDispatch *pDispWordEditor;
  46.                 MSWord::_Document document;
  47.  
  48.                  if (SUCCEEDED(pInsp->get_WordEditor(&pDispWordEditor)))
  49.                  {
  50.                     pDispWordEditor->QueryInterface(__uuidof(MSWord::_Document), (LPVOID *)&document);
  51.                  }
  52.             }
  53.         }
  54.     }
  55.     return;
  56. }
Feb 27 '08 #1
1 5117
weaknessforcats
9,207 Expert Mod 8TB
Does this help?
http://msdn2.microsoft.com/en-us/library/4bk23z1z.aspx ?
Feb 27 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Sasha | last post: by
reply views Thread by David Lozzi | last post: by
2 posts views Thread by Mike | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.