unexcepted exception when using Redemption's SaveAs in Java/C++ interop scenario

A

andy

Here is my scenario:

I have a java client and am developing a native Outlook add-in
component. I tried to use Redemption to bypass the Outlook security
warning and so far it works well (BTW, Redemption is a neat stuff).
However, when I tried to call _ISafeItem.SaveAs from native (C++) code
(I put my code snippet down below), it got an unexception exception:

Unexpected Signal : unknown exception code (0xeedfade) occurred at
PC=0x77E73887
Function=RaiseException+0x50
Library=E:\WINDOWS\system32\kernel32.dll

I also tried some standalone native code (using VB) to do the SaveAs.
no problem. So now I am really suspect the failure has something to do
with Java/native interop. Can that be something permission related? I
will appreciate any suggestion/comment. Thanks in advance.

-- Andy


P.S. my code snippet to call SaveAs to save the RFC raw data (which is
part of requirement).

/*************************************************/
JNIEXPORT jboolean JNICALL Java_Test_saveMailAsRFC822
(JNIEnv *env, jobject jobj, jstring filename, jstring messageID)
{
/*** I code a helper class so somehow I get the MailItem **/

// get ISafeMailItemPtr from MessageHelper
jboolean isCopy;
const wchar_t * nativeMailID = env->GetStringChars(messageID,
&isCopy);
OL::_MailItemPtr pMailItem =
helper->GetMailItemFromMap(_bstr_t(nativeMailID));

if (isCopy == JNI_TRUE)
{
env->ReleaseStringChars(messageID, nativeMailID);
}

const wchar_t * nativeFilename = env->GetStringChars(filename,
&isCopy);

// find Redemption class ID
CLSID clsid;
CLSIDFromProgID(L"Redemption.SafeMailItem", &clsid);

// Create instance of Redemption::SafeMailItem
Redemption::ISafeMailItemPtr pItem;

HRESULT hr = CoCreateInstance(clsid, NULL,
CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER,
__uuidof(Redemption::ISafeMailItem),
(void**)&pItem);

if(FAILED(hr))
{
printf("Redemption.dll is not registered. : Error!!");
return NULL;
}

pItem->AddRef();
pItem->Item = (IDispatch *)pMailItem;

/**** I tried some simple test here, just make sure the
MailItem pointer I got worked. And both statements executed fine ***/

printf((LPCSTR)pMailItem->Subject);
printf((LPCSTR)pItem->To);

/*** try to call SaveAs. However, exception happened here
****/

hr = pItem->SaveAs(_bstr_t(nativeFilename), Redemption::blush:lRFC822);

if (isCopy == JNI_TRUE)
{
env->ReleaseStringChars(filename, nativeFilename);
}

/**** some other unrelated stuff ****/
}
 
A

andy

I also did a sanity test code and found out if calling

Outlook::_MailItem SaveAs, no exception will be thrown. Of course, OOM
will prompt the security warning and really provides no way to export
RFC822 raw data. So that is not an option for me.

Anyone can shred some light on how ISafeMailItem.SaveAs is implemented
and why it will cause exception? Dmitry?

Thanks a lot.
-- Andy
 
A

andy

Hi, Dmitry,

I did. For now I hardcode the filename in native just try to eliminate
that possibility. In fact, I wrote a test native method only to
explore the issue (called from Java). From where I call
Outlook::_MailItem SaveAs method with same filename would succeed.

....... // set pMAPI to pointer to namespace
OL::MAPIFolderPtr inboxFolder =
pMAPI->GetDefaultFolder(OL::blush:lFolderInbox);

OL::_MailItemPtr pMailItem;
HRESULT hRes= inboxFolder->Items->GetFirst()->QueryInterface(__uuidof(OL::_MailItem),
(void **)&pMailItem);
if (FAILED(hRes))
{
printf("First item is not mail item.");
return;
}

// find Redemption class ID
CLSID clsid;
CLSIDFromProgID(L"Redemption.SafeMailItem", &clsid);

// Create instance of Redemption::SafeMailItem
Redemption::ISafeMailItem* pItem;

HRESULT hr = CoCreateInstance(clsid, NULL,
CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER,
__uuidof(Redemption::ISafeMailItem),
(void**)&pItem);

if(FAILED(hr))
{
printf("Redemption.dll is not registered. : Error!!");
return;
}

pItem->AddRef();
pItem->Item = (IDispatch *)pMailItem;

// if I call following comment line instead of next statement,
I would succeed (with the Outlook secruity warning):
// hr = pMailItem->SaveAs(_bstr_t(L"C:\OL_RFC.txt"),
OL::blush:lHTML);


hr = pItem->SaveAs(_bstr_t(L"C:\Redemption_RFC.txt"),
Redemption::blush:lRFC822); // this will trigger the unexpected exception
if (FAILED(hr))
{
printf("Failed to save.");
}
pMailItem->Release();
pItem->Release();

............. // other unrelated stuff.


Thanks,
-- Andy
 
D

Dmitry Streblechenko \(MVP\)

Does it happen with any message or just with some? Can you send me a message
(zipped) that exhibits this problem to my private e-mail address?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Top