Click here to Skip to main content
15,881,380 members
Articles / Desktop Programming / ATL
Article

Programmatically Make Folder in Outlook by using addins

Rate me:
Please Sign up or sign in to vote.
1.60/5 (3 votes)
23 Apr 2007 35.6K   447   16   3
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 .
C++
"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
C++
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.
C++
#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

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

please replace by

C++
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



Comments and Discussions

 
GeneralDude, your images don't show Pin
babalao13-Apr-07 4:04
babalao13-Apr-07 4:04 
GeneralRe: Dude, your images don't show Pin
ashu_om15-Apr-07 20:08
ashu_om15-Apr-07 20:08 
Generalhi all Pin
ashu_om12-Apr-07 20:53
ashu_om12-Apr-07 20:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.