We help IT Professionals succeed at work.

Add an Outlook contact in visual C++ 6

B_B_Boris
B_B_Boris asked
on
1,288 Views
Last Modified: 2012-05-05
Hi there,

I need to write an Outlook addin in visual C++ 6 which create a new contact. I used the code given by http://support.microsoft.com/kb/220600/fr?spid=2520&sid=global but it doesn't work. I get many error messages whose first ones are given below.

Thanks in advance

c:\addin\addin.h(83) : error C2259: '_Application' : cannot instantiate abstract class due to following members:
        c:\addin\debug\msoutl9.tlh(837) : see declaration of '_Application'
c:\addin\addin.h(83) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not define
d
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface'
c:\addin\addin.h(83) : warning C4259: 'unsigned long __stdcall IUnknown::AddRef(void)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(113) : see declaration of 'AddRef'
c:\addin\addin.h(83) : warning C4259: 'unsigned long __stdcall IUnknown::Release(void)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(115) : see declaration of 'Release'
c:\addin\addin.h(83) : warning C4259: 'long __stdcall IDispatch::GetTypeInfoCount(unsigned int *)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\oaidl.h(2697) : see declaration of 'GetTypeInfoCount'
c:\addin\addin.h(83) : warning C4259: 'long __stdcall IDispatch::GetTypeInfo(unsigned int,unsigned long,struct ITypeInfo ** )' : pure virtual functio
n was not defined
        c:\program files\microsoft visual studio\vc98\include\oaidl.h(2700) : see declaration of 'GetTypeInfo'
c:\addin\addin.h(83) : warning C4259: 'long __stdcall IDispatch::GetIDsOfNames(const struct _GUID &,unsigned short ** ,unsigned int,unsigned long,lon
g *)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\oaidl.h(2705) : see declaration of 'GetIDsOfNames'
c:\addin\addin.h(83) : warning C4259: 'long __stdcall IDispatch::Invoke(long,const struct _GUID &,unsigned long,unsigned short,struct tagDISPPARAMS *
,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\oaidl.h(2712) : see declaration of 'Invoke'
c:\addin\addin.h(83) : warning C4259: 'long __stdcall Outlook::_Application::get_Application(struct Outlook::_Application ** )' : pure virtual functi
on was not defined
        c:\addin\debug\msoutl9.tlh(908) : see declaration of 'get_Application'
c:\addin\addin.h(83) : warning C4259: 'long __stdcall Outlook::_Application::get_Class(enum Outlook::OlObjectClass *)' : pure virtual function was no
t defined
Comment
Watch Question


What version of outlook are you using?

Author

Commented:
2000
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
Could you post the code such as it really is? The error messages apparently don't really reference the snippets given on that page.

Author

Commented:
Thank you for your message, here is the code :

#ifndef __ADDIN_H_
#define __ADDIN_H_

#include "resource.h"       // main symbols
#include <afxinet.h>
#import "C:\Program Files\Fichiers communs\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids

// Define this according to the Outlook Object
// Model version you are compiling under
//#define OUTL11      // Outlook 2003
//#define OUTL10      // Outlook 2002
#define OUTL9            // Outlook 2000

#pragma warning(disable:4146)

#if defined(OUTL11) // Outlook 2003
      #import "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\mso.dll" \
            no_namespace
      #import "C:\Program Files\Microsoft Office\OFFICE11\msoutl.olb" \
            rename_namespace("Outlook")
#elif defined(OUTL10) // Outlook 2002
      #import "C:\Program Files\Common Files\Microsoft Shared\OFFICE10\mso.dll" \
            no_namespace, rename("DocumentProperties", "DocProps")
      #import "C:\Program Files\Microsoft Office\OFFICE10\msoutl.olb" \
            rename_namespace("Outlook")
#elif defined(OUTL9) // Outlook 2000
      #import "C:\Program Files\Microsoft Office\Office\mso9.dll" \
            no_namespace, rename("DocumentProperties", "DocProps")
      #import "C:\Program Files\Microsoft Office\Office\msoutl9.olb" \
            rename_namespace("Outlook")
#endif // OUTL11

#pragma warning(default:4146)

using namespace Outlook;

...

      STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom)
      {

            // Start Outlook.
            // If it is already running, you'll use the same instance...
            _Application olApp;
            COleException e;
            if(!olApp.CreateDispatch("Outlook.Application", &e))
            {
                  CString str;
                str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc);
                  AfxMessageBox(str, MB_SETFOREGROUND);
                  return;
            }

            // Logon. Doesn't hurt if you are already running and logged on...
            NameSpace olNs(olApp.GetNamespace("MAPI"));
            COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
            olNs.Logon(covOptional, covOptional, covOptional, covOptional);
   
            // Create and open a new contact
            _ContactItem olItem(olApp.CreateItem(2));
   
            // Setup Contact information...
            olItem.SetFullName("James Smith");
            COleDateTime bdDate;
            bdDate.SetDate(1975, 9, 15);
            olItem.SetBirthday(bdDate);
            olItem.SetCompanyName("Microsoft");
            olItem.SetHomeTelephoneNumber("704-555-8888");
            olItem.SetEmail1Address("someone@microsoft.com");
            olItem.SetJobTitle("Developer");
            olItem.SetHomeAddress("111 Main St.\nCharlotte, NC 28226");
   
            // Save Contact
            olItem.Save();

            return E_NOTIMPL;
      }
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
Ah, make that

#import "C:\Program Files\Fichiers communs\Designer\MSADDNDR.DLL" named_guids

"raw_interfaces_only" is responsible for the "pure virtual function was not defined" errors.

Author

Commented:
Thank you for your help. I replaced

//#import "C:\Program Files\Fichiers communs\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids

with

#import "C:\Program Files\Fichiers communs\Designer\MSADDNDR.DLL" named_guids

and the error messages given previously disappeared. But now, I get

c:\addin.h(59) : error C2065: '_IDTExtensibility2' : undeclared identifier
c:\addin.h(59) : error C2065: 'IID__IDTExtensibility2' : undeclared identifier
c:\addin.h(59) : error C2065: 'LIBID_AddInDesignerObjects' : undeclared identifier
c:\addin.h(60) : fatal error C1903: unable to recover from previous error(s); stopping compilation
syncml_synchro_addin.cpp
c:\addin.h(59) : error C2065: '_IDTExtensibility2' : undeclared identifier
c:\addin.h(59) : error C2065: 'IID__IDTExtensibility2' : undeclared identifier
c:\addin.h(59) : error C2065: 'LIBID_AddInDesignerObjects' : undeclared identifier
c:\addin.h(60) : fatal error C1903: unable to recover from previous error(s); stopping compilation

Author

Commented:
I found another way to add a contact which compiles and works !

_ApplicationPtr pApp("Outlook.Application");
_NameSpacePtr pNamespace = pApp->GetNamespace("MAPI");
MAPIFolderPtr pFolder = pNamespace->GetDefaultFolder(olFolderContacts);
_ItemsPtr pItems = pFolder->GetItems();

// Create and open a new contact
_ContactItemPtr pNewContact;
pNewContact = pApp->CreateItem(olContactItem);
pNewContact->put_LastName(OLESTR("Zorglub"));
pNewContact->put_FirstName(OLESTR("Titi"));
pNewContact->Save();
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.