_MailItem->GetSendOn(&date) throws an exception

  • Thread starter nikolayds via OfficeKB.com
  • Start date
N

nikolayds via OfficeKB.com

Hi All,

I am migrating my plugin from 2003 to 2007 Outlook.

A following code is throwing me exception:
<code>
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;

</code>
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

<code>
#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll"
rename("RGB", "RGB_") \
rename("DocumentProperties", "DocProps") rename("FindText", "WordFindText") \

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

using namespace Office;
#import "C:\Program Files\Microsoft Office\Office12\MSOUTL.OLB" rename
("CopyFile", "CopyFile_") \
rename("PlaySound", "OutlookPlaySound")\
rename_namespace("Outlook")
using namespace Outlook;
</code>

The code is working just fine in OL 2003
 
N

Nikolay Sarmadzhiev

Hi All,

I am migrating my plugin from 2003 to 2007 Outlook.

A following code is throwing me exception:
<code>
                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;

</code>
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

<code>
#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll"
rename("RGB", "RGB_") \
        rename("DocumentProperties", "DocProps") rename("FindText", "WordFindText") \

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

using namespace Office;
#import "C:\Program Files\Microsoft Office\Office12\MSOUTL.OLB" rename
("CopyFile", "CopyFile_") \
        rename("PlaySound", "OutlookPlaySound")\
        rename_namespace("Outlook")
using namespace Outlook;
</code>

The code is working just fine in OL 2003

Here is the fix: (must use a raw method and queryInterface)
raw_Item(covIndex,&olSelectedItem);
if(FAILED(hr)) continue;

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

if(FAILED(hr)) continue;

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

After that the methods are working fine in OL 2007.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top