Windows XP 平板电脑版ATLVisual Studio 6Visual Studio .NET 2003Windows 2000Visual C++ 6.0Windows XP中级开发Visual StudioWindowsC++
通过插件以编程方式在 Outlook 中创建文件夹






1.60/5 (3投票s)
2007年4月13日

36412

480
使用 VC++6.0 中的 ATL 插件在 Outlook 2000 中创建文件夹。
引言
本文基于 Outlook 的 ATL 插件,以及使用插件在 Outlook 中编程创建文件夹。
背景
理解如何创建插件以及使用 VC++6.0 中的 ATL 插件在 Outlook 2000 中创建文件夹。
Using the Code
步骤如下:
- 首先打开 VC++6.0 和 ATL COM 应用向导,并将项目名称写入 MakeFolder。
- 使用 ATL 对象向导插入 ATL 示例对象。接口名称为 Interface_Folder,它继承自 Idispatch 接口。
- 从 Microsoft add designer 类型库中实现接口
- 选择 _ IDTExtensibility2 并按确定按钮以实现接口。
- 将代码粘贴到 OnConnection 事件中。
"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;
}
- 从文件视图打开 .reg 文件以进行注册表操作,并将此代码粘贴到向导生成代码之后。这对于调用 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'
}
}
}
}
}
}
}
- 将代码粘贴到 stdafx.h 文件中,并根据您的 PC MSoffice 设置更改路径。
#import "C:\Program Files\Microsoft Office\Office\MSOUTL9.olb"
rename_namespace("Outlook"), named_guids, raw_interfaces_only
using namespace Outlook;
关注点
欢迎大家提出关于错误和改进的建议,关于这篇小文章。
帮助解决错误
if (InlineIsEqualGUID(*arr[i],riid))
请替换为
if (ATL::InlineIsEqualGUID(*arr[i],riid))