开发outlook add-in的问题

lincker 2003-06-04 06:30:27
我要做一个outlook的插件的dll,已经实现在outlook中加入按钮,点击按钮可以响应事件,弹出个对话框之类的。
但是我如何能获得选中的mail呢??
CComPtr<Outlook::_Explorer> spExplorer;
m_spApp->ActiveExplorer(&spExplorer);
CComPtr<Outlook::Selection> spSelection;
HRESULT hr = spExplorer->get_Selection(&spSelection);
这样取出来的好像都不对,总是非法。
还请高手指点!
...全文
104 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
brave_heart 2003-06-05
  • 打赏
  • 举报
回复
>> spSelection->Item(x,(IDispatch**)&olItem);---->这里取到的olitem就是空的,>> 哪里错了??

LPDISPATCH olSelectedItem;

COleVariant covIndex;

covIndex.vt = VT_I4;
covIndex.lVal = i; //index

olSelectedItem = olSel.Item(covIndex); // Get the selected item

Yaoling 2003-06-05
  • 打赏
  • 举报
回复
CComPtr<Outlook::_Explorer> spExplorer;
m_spApp->ActiveExplorer(&spExplorer);
CComQIPtr<Outlook::Selection> spSelection;
HRESULT hr = spExplorer->get_Selection(&spSelection);

=================================
change CComPtr to CComQIPtr ....
good lucky.
brave_heart 2003-06-05
  • 打赏
  • 举报
回复
Here is some VB code, but I think you can easily translate it into C++

The item(s) selected in a folder view are the
Application.ActiveExplorer.Selection collection.

A better way to get the current Inspector is
Application.ActiveInspector.

Put them together and you get this code to get an open item or the first
item selected in the folder, regardless of which is the active window:

Function GetCurrentItem() As Object
Dim objApp As Application

Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem =
objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select

Set objApp = Nothing
End Function
Yaoling 2003-06-05
  • 打赏
  • 举报
回复
如果你想简单点的话
可以由*.old生成一个新的类.
然后由Application app;
app.AttachDispatch(IDisapatch);
Yaoling 2003-06-05
  • 打赏
  • 举报
回复
CComQIPtr <Outlook::_MailItem> olItem;
=========================================
chang CComPtr to CComQIPtr
spSelection->Item(x,&olItem);
-----------------------------------
error : can't to force transform this type to IDispatch**;
Why ?? I don't know ..
lincker 2003-06-05
  • 打赏
  • 举报
回复
CComQIPtr<Outlook::Selection> spSelection;
HRESULT hr = spExplorer->get_Selection(&spSelection);
if(FAILED(hr))
return;
VARIANT x ;
x.vt = VT_I2;
x.iVal = 1 ;
CComPtr <Outlook::_MailItem> olItem;
spSelection->Item(x,(IDispatch**)&olItem);---->这里取到的olitem就是空的,哪里错了??
lincker 2003-06-05
  • 打赏
  • 举报
回复
我就是这个不太明白,vb中
Set GetCurrentItem =
objApp.ActiveExplorer.Selection.Item(1)
而在vc中spExplorer->get_Selection(&spSelection);后
spSelection->Item却需要两个参数(variant index,Idispatch ** Item)
这里应该怎么写获得item?而且该怎么显示出来这个item???
phiger 2003-06-04
  • 打赏
  • 举报
回复
mark firstly

3,248

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧