473,748 Members | 2,602 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 5685
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
1244
by: San | last post by:
Hello How can we connect to Outlook Express through Yahoo Messenger Thanks in advance.
9
1975
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
1233
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
1327
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
1121
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
1540
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
4237
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
1137
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
4393
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
8984
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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
9363
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
6793
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
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
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
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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.