Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Programmatically Make Folder in Outlook by using addins

0.00/5 (No votes)
23 Apr 2007 1  
Making Folder in outlook 2000 by using ATL addins in VC++6.0.

Introduction

This article is based on the ATL addin for outlook, and Pro grammatically Making Folder in Outlook by using addins.

Background

Understanding how to create addins and Making Folder in outlook 2000 by using ATL addins in VC++6.0.

Using the Code

Steps Involves :-

  1. First open VC++6.0 and ATL COM App Wizard and write name of project MakeFolder.
  1. Insert ATL sample object by using ATL object Wizard. Name of interface Interface_Folder which is derived from Idispatch interface.
  2. Implement Interface from Microsoft add designer type Libraries

Screenshot - image001.jpg
Screenshot - image002.jpg

  1. Choose _ IDTExtensibility2 and press ok button for implement interface.

Screenshot - image003.jpg

  1. Paste code in the OnConnection event .
"STDMETHOD(OnConnection)(IDispatch * Application, ext_ConnectMode ConnectMode,
     IDispatch * AddInInst, SAFEARRAY * * custom)
{
    ::MessageBox (0,"This is Make Folder addin","Make folder addin",0);
    CComQIPtr <Outlook::_Application> spApp(Application); 
    ATLASSERT(spApp);

    CComPtr <Outlook::_NameSpace> olNs;
    CComQIPtr <Outlook::_Folders> spMainFolderList;
    CComQIPtr <Outlook::_Folders> spPersonalFolderList;
    CComQIPtr <Outlook::MAPIFolder> spPersonalFolder;
    CComQIPtr <Outlook::MAPIFolder> spNewFolder;

    // Folder type can be any of the following:
    // STRFOLDERTYPE NAME
    //----------------------------------
    // MailItems IPF.Note
    // ContactItems IPF.Contact
    // AppointmentItems IPF.Appointment
    // NoteItems IPF.StickyNote
    // TaskItems IPF.Task
    // JournalItems IPF.Journal

    CComVariant varFolderType("IPF.Note");
    CComBSTR bstr_temp("test_folder_Name"); //Name of folder

    //Start a MAPI Session
    CComQIPtr <Outlook::_Application> m_spOutlookApp(Application); 
    ATLASSERT(m_spOutlookApp);

    m_spOutlookApp = spApp; 

    m_spOutlookApp->get_Session(&olNs);

    if(olNs == NULL)
        return -1;

    //Get the folder list of the current session
    olNs->get_Folders(&spMainFolderList);
    //Get the first folder (this should be the Personal Folders)

    spMainFolderList->GetFirst(&spPersonalFolder);
    //Get the folder list of the Personal Folders folder
    spPersonalFolder->get_Folders(&spPersonalFolderList);
    //Add to the personal folder list.
    spPersonalFolderList->Add(bstr_temp, varFolderType,&spNewFolder); 

    return E_NOTIMPL;
}
  1. Open .reg file for registry from file view and paste this code after wizard generate code It is important for Calling COM dll
HKCU
{
    Software 
    { 
        Microsoft
        { 
            Office 
            { 
                Outlook 
                {
                    Addins 
                    { 
                        'MakeFolder.Interface_Folder'
                        { 
                            val FriendlyName = s 'MakeFolder My Addin'
                                val Description = 
                                    s 'MakeFolder MY Outlook Addin'
                                val LoadBehavior = d '00000003'
                                val CommandLineSafe = d '00000000' 
                        } 
                    } 
                } 
            } 
        } 
    } 
}
  1. Paste on stdafx.h file and changes path according to your PC MSoffice setting.
#import "C:\Program Files\Microsoft Office\Office\MSOUTL9.olb" 
    rename_namespace("Outlook"), named_guids, raw_interfaces_only

using namespace Outlook;

Points of Interest

welcome all suggestion and quires for error and improvement on this small Artical.

Error Solution for Help

if (InlineIsEqualGUID(*arr[i],riid))

please replace by

if (ATL::InlineIsEqualGUID(*arr[i],riid))

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here