473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 5651
weaknessforcats
9,208 Expert Mod 8TB
Does this help?
http://msdn2.microsoft.com/en-us/library/4bk23z1z.aspx ?
Feb 27 '08 #2

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

Similar topics

0
by: San | last post by:
Hello How can we connect to Outlook Express through Yahoo Messenger Thanks in advance.
9
by: Tom Dacon | last post by:
I have a little desktop application (it happens to be a Windows Forms analog clock) that's written in VB.Net (2003). I placed a shortcut in my Startup program group to start it up when I log on. I...
0
by: Bob Dydd | last post by:
Hi Everybody I am looking for a way to connect and disconnect to the Ms Outlook Inbox programmatically from a command button on a form . At the moment it is easy enough to do by going to the...
0
by: Sasha | last post by:
Hi All How to connect to "Outlook Express". The scenerio is that an ASPX page (C#) should retrieve the contact info from address book of "Outlook Express", Thanks Sasha
0
by: David Lozzi | last post by:
Hi All, I've run into a dilema. I am currently working on a web (ASP.NET w/ VB) project that will potentially contain 2000 members or so. The staff want to be able to access their information as...
2
by: Mike | last post by:
I need to create a front end for the users to enter in some data, but the data needs to go to a folder on the exchange server. How can I add, view, and modify items in outlook (exchange) folders. I...
1
by: Jim H | last post by:
I want to write an outlook plug-in or even a separate app if necessary to connect to an exchange server to get mail off of it. My outlook is currently connected to Exchange server A, I need to get...
0
by: snoconegod | last post by:
Hello, I already have my PST file open within Outlook (it's actually a PST created by a Sharepoint import). How can I access the information within it? I seems to me that using the "AddStore"...
1
by: vibhavleo | last post by:
I am using the Microsoft Office 11.0 Object library to connect to outlook. My code is as follows: _ApplicationPtr application("Outlook.Application"); CComPtr<_NameSpace> ns;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.