Outlook COM+ add-in newbie question

  • Thread starter Michael Böhnisch
  • Start date
M

Michael Böhnisch

Hi!

I am a newbie to COM+ and Office development and also not familiar with VB. However, using code snippets and documentation I found in the web, I was able to set up and deploy a C++ "Shared Add-In" to Outlook 2002 in Visual Studio .NET 2003 (EA).

I figured out how to implement a working toolbar and button for Outlook that triggers an event callback function when clicked. But now I'm stuck.

Inside the event routine I need to access the body text of each email the user selected in the current folder view:

for ( each email selected ) {
std::string body = email.bodytext;
DoSomething( body );
}

Is there a kind soul outside that could sketch me out how to do this? I would also be grateful for pointers to online documentation or books that cover COM+ and Office add-in development using VC++.

Thank you in advance,

Michael.
 
M

Michael Böhnisch

Hi All

I figured out myself how to do it, my problems stemmed from a missing cast to IDispatch**

FYI, here is my code

// retrieve Explorer, m_spApp is application object
CComPtr<Outlook::_Explorer> spExplorer
m_spApp->ActiveExplorer( &spExplorer )

// ask for list of currently selected email items
CComPtr<Outlook::Selection> spSelection
hr = spExplorer->get_Selection( &spSelection )
if ( FAILED( hr ) ) return

// retrieve number of items in the list
long count
hr = spSelection->get_Count( &count )
if ( FAILED( hr ) ) return

// loop through the selected mails
for ( int i = 1; i <= count; ++i )

CComVariant index( i )

// get ith selected mai
CComPtr<Outlook::_MailItem> spItem
hr = spSelection->Item( index, (IDispatch**) &spItem ); // Here I missed the cas
if ( FAILED( hr ) ) return

// mail body comes as wide-char BST
CComBSTR bbody
hr = spItem->get_Body( &bbody )
if ( FAILED( hr ) ) return

// convert BSTR to std::strin
CW2A cbody( bbody )
const std::string body( cbody )

// call my stuff
DoSomething( body )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top