Outlook - _MailItem->GetSendOn(&date) throws an exception

Asked By nikolayds via OfficeKB.com
26-Feb-10 07:17 PM
Hi All,

I am migrating my plugin from 2003 to 2007 Outlook.

A following code is throwing me exception:
COleVariant covIndex;
covIndex.vt = VT_I4;
covIndex.lVal = 1;
olSelectedItem = olSel->Item(covIndex);

CComQIPtr<Outlook::_MailItem> pMailItem(olSelectedItem);
CComPtr<Outlook::_MailItem> pItemT = pMailItem;

Outlook::OlObjectClass oc = pItemT->GetClass(); //works

DATE dt = 0;
dt = pItemT->SendOn; //Fails with exception


CLSID clsid;
hr = ::CLSIDFromProgID(L"Redemption.SafeMailItem", &clsid);
CComPtr<Redemption::ISafeMailItem>	 spSafeMailItem;
hr = ::CoCreateInstance(clsid, NULL,  CLSCTX_INPROC_SERVER,__uuidof
(ISafeMailItem),(void**)&spSafeMailItem );
hr = spSafeMailItem->put_Item(pItemT);
BSTR name = SysAllocStringLen(L"", 1000);
hr = spSafeMailItem->get_SenderName(&name); //works

return;

Exception is address violation.

I strongly suspect the issue is with how the params are passed, because all
functions with parameters on Outlook::_MailItem are failing where all others
are OK.

Here is what I have in StdAfx

rename("RGB", "RGB_") \
rename("DocumentProperties", "DocProps") rename("FindText", "WordFindText") \

rename("PlaySound", "OfficePlaySound")\
rename_namespace("Office")

using namespace Office;
("CopyFile", "CopyFile_") \
rename("PlaySound", "OutlookPlaySound")\
rename_namespace("Outlook")
using namespace Outlook;

The code is working just fine in OL 2003

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/outlook-prog-addins/201002/1
CLSIDFromProgID
(1)
Redemption.SafeMailItem
(1)
Outlook
(1)
Office
(1)
CComQIPtr
(1)
SysAllocStringLen
(1)
ISafeMailItem
(1)
CoCreateInstance
(1)
  Nikolay Sarmadzhiev replied to nikolayds via OfficeKB.com
02-Mar-10 01:17 PM
lSelectedItem); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
ailItem;
Class(); //works =A0 =A0 =A0
tion
eMailItem", &clsid);
=A0 =A0 =A0 spSafeMailItem;
=A0CLSCTX_INPROC_SERVER,__uuidof
);
me); //works
ll
ers
tlook-prog-addins/201002/1

Here is the fix: (must use a raw method and queryInterface)
HRESULT hr =3D olSel-
if(FAILED(hr)) continue;

Outlook::_MailItem * pMailItem =3D NULL;
hr =3D olSelectedItem->QueryInterface(__uuidof(Outlook::_MailItem),
(void**)&pMailItem);

if(FAILED(hr)) continue;

//CComQIPtr<Outlook::_MailItem> pMailItem(olSelectedItem);
CComPtr<Outlook::_MailItem> pItem =3D pMailItem;

After that the methods are working fine in OL 2007.
Create New Account
help
Handling application.quit event Outlook Hello, i am developing an exe application and i use global object to declare outlook application withevents. I use outlook 2007 sp2 and i am having trouble releasing my variable references or reusing then. I use this code : Public Class StartOE Private WithEvents o As Outlook.Application = Nothing Private ns As Outlook.NameSpace = Nothing Private omFolder As Outlook.MAPIFolder = Nothing Public Sub New() If detectOutlook() Then o = GetObject(, "Outlook.Application") Else o = New Outlook.Application End If Try ns = o.GetNamespace("MAPI") ' get namespace ns.Logon("", "", True, True) 'log
Saving attachments to folder from public folder Outlook Hey there! I am currently working on a project that involves merging data from many into one Excel workbook for analysis. The csv files are sent to a public folder (outlook: \ Public Folders \ All Public Folders \ etc. . .) I thought the easiest way to do this would be to import the data straight from Outlook to the Excel file but after much painful testing I could not get it to main mailbox folders, not public and am unsure why. . . I have almost no experience with Outlook coding so any help is appreciated! This is the current code: If there is a instead of using a selection, that is fine too! Public Sub SaveAttachments() Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath
Additional Phone Number Fields Outlook Outlook newbie. . . Is it possible to add additional phone number fields to Outlook 2007 contacts? Business and Business 2 already exist but I need Business 3, Business 4, etc. Can that be done. If so, how? Thanks. Peter Outlook Contacts Discussions SQL Express (1) SharePoint (1) InfoPath (1 Outlook 2007 (1) Office 2007 (1) Office 2010 (1) Outlook (1) Office (1) You can design a custom form. See this: http: / / www.outlookcode.com
Problem seeing some characters when sending email to Outlook client Outlook Using VB6, I am sending an HTML email using SMTP. I am having a problem like a bullet point that looks like an arrow) thru email that is received in Outlook. The weird thing is some Outlook client can see the arrow fine, some can not. My Outlook 2003 used to be able to see the arrow ok, but now it does not Some Outlook 2007 can see it ok, some cannot. I can see the arrow fine in Gmail a problem with: = E2 = 96 = BA That arrow character becomes this in some of the Outlook client: – Thank you for your help. This is my code: Set poSendMail = 3D New clsSendMail Enlighten The Solar Energy Industry< / A> <o:p> < / o:p> < / SPAN> < / FONT> < / P> < / TD> < / TR> Outlook General Discussions Microsoft Word (1) Tony Tony Toews Microsoft Access (1) Outlook 2003 (1) Outlook
Looking for good email program? Outlook Hi forum members, This is the first time I have posted at this forum, and to an excellent internet / web based email. With Microsoft, it appears I have two choices, Outlook, or Outlook Express. Up front I am stating, not interested in all the bells and whistles that that exists, whether it is free, or, I have to pay for it. So, between Outlook and Outlook Express, what are the pros and cons about one versus the other? Please do not about the stuff I have stated I am not interested in. Simply want to compare Outlook vs Outlook Express's email program and how either will serve me best. My needs: 1 - I do not waste anybody's time with stuff that is not relevant to my question. Outlook or Outlook Express? For EMAIL PURPOSES. One or the other, Why vs Why Not? After