473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connect to outlook from C++

2 New Member
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::_Docum ent' : 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 5680
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
1239
by: San | last post by:
Hello How can we connect to Outlook Express through Yahoo Messenger Thanks in advance.
9
1972
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 have put no code in the application whatsoever to do internet communications, and yet when it starts up at logon I've begun getting notification dialogs from my software firewall that the app wants to connect to the internet. It doesn't happen...
0
1231
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 database container and doing the following: 1. select file 2. select Get external data
0
1324
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
1117
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 necessary and email whomever as necessary. It will be too cumbersome for the staff to log into the application to get a few emails manually. It would be best to load it into an Outlook contact list, similiar to Sharepoint. What does it take to...
2
1537
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 would be using outlook as the database.
1
4232
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 mail from Exchange server B and put it on Exchange server A. I'm tired of using multiple Outlook profiles. How do I connect to an exchange server programmatically and get mail? I'd like to do it as a plug in, but if it needs to be a separate...
0
1134
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" method won't work, because that tries to reattach the PST that Outlook is already accessing. Am I way off here?
1
4389
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; CComPtr<_NameSpace> session; hr = application->GetNamespace(CComBSTR("MAPI"),&session.p); if(hr != S_OK) return hr; hr = application->get_Session(&session.p); if(hr != S_OK) return hr; hr =...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.