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 :-
- First open VC++6.0 and ATL COM App Wizard and write name of project MakeFolder.
- Insert ATL sample object by using ATL object Wizard. Name of interface Interface_Folder which is derived from Idispatch interface.
- Implement Interface from Microsoft add designer type Libraries
- Choose _ IDTExtensibility2 and press ok button for implement interface.
- 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;
}
- 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'
}
}
}
}
}
}
}
- 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))