472,789 Members | 1,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 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"
  4. // Define this according to the Outlook Object
  5. // Model version you are compiling under
  6. #define OUTL12    // Outlook 2007
  8. #pragma warning(disable:4146)
  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
  17. #pragma warning(default:4146)
  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);
  31.         if (FAILED(hr))
  32.         {
  33.             return;
  34.         }
  36.         pUnk->Release();
  38.         Outlook::_ApplicationPtr outlookApp(pDispApp);
  40.         if(outlookApp->ActiveInspector()!=NULL)
  41.         {
  42.             Outlook::_InspectorPtr pInsp(outlookApp->ActiveInspector());
  43.             if(pInsp!=NULL)
  44.             {
  45.                 IDispatch *pDispWordEditor;
  46.                 MSWord::_Document document;
  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 5576
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

by: San | last post by:
Hello How can we connect to Outlook Express through Yahoo Messenger Thanks in advance.
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...
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...
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
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...
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...
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...
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"...
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;...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.