PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Program Addins unexcepted exception when using Redemption's SaveAs in Java/C++ interop scenario

Reply

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

 
Thread Tools Rate Thread
Old 14-06-2004, 11:44 AM   #1
andy
Guest
 
Posts: n/a
Default unexcepted exception when using Redemption's SaveAs in Java/C++ interop scenario


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:lRFC822);

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

/**** some other unrelated stuff ****/
}
  Reply With Quote
Old 14-06-2004, 08:47 PM   #2
andy
Guest
 
Posts: n/a
Default Re: unexcepted exception when using Redemption's SaveAs in Java/C++ interop scenario

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

gogowings@hotmail.com (andy) wrote in message news:<a42d0bcf.0406140244.3c508517@posting.google.com>...
> 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:lRFC822);
>
> if (isCopy == JNI_TRUE)
> {
> env->ReleaseStringChars(filename, nativeFilename);
> }
>
> /**** some other unrelated stuff ****/
> }

  Reply With Quote
Old 15-06-2004, 01:28 AM   #3
Dmitry Streblechenko \(MVP\)
Guest
 
Posts: n/a
Default Re: unexcepted exception when using Redemption's SaveAs in Java/C++ interop scenario

Did you make sure nativeFilename is valid?

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


"andy" <gogowings@hotmail.com> wrote in message
news:a42d0bcf.0406140244.3c508517@posting.google.com...
> 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:lRFC822);
>
> if (isCopy == JNI_TRUE)
> {
> env->ReleaseStringChars(filename, nativeFilename);
> }
>
> /**** some other unrelated stuff ****/
> }



  Reply With Quote
Old 15-06-2004, 08:45 AM   #4
andy
Guest
 
Posts: n/a
Default Re: unexcepted exception when using Redemption's SaveAs in Java/C++ interop scenario

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: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:lHTML);


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

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


Thanks,
-- Andy

"Dmitry Streblechenko \(MVP\)" <dmitry@dimastr.com> wrote in message news:<OG1v5#mUEHA.2972@TK2MSFTNGP12.phx.gbl>...
> Did you make sure nativeFilename is valid?
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
>
> "andy" <gogowings@hotmail.com> wrote in message
> news:a42d0bcf.0406140244.3c508517@posting.google.com...
> > 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:lRFC822);
> >
> > if (isCopy == JNI_TRUE)
> > {
> > env->ReleaseStringChars(filename, nativeFilename);
> > }
> >
> > /**** some other unrelated stuff ****/
> > }

  Reply With Quote
Old 15-06-2004, 09:49 PM   #5
Dmitry Streblechenko \(MVP\)
Guest
 
Posts: n/a
Default Re: unexcepted exception when using Redemption's SaveAs in Java/C++ interop scenario

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


"andy" <gogowings@hotmail.com> wrote in message
news:a42d0bcf.0406142345.5445b278@posting.google.com...
> 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: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:lHTML);
>
>
> hr = pItem->SaveAs(_bstr_t(L"C:\Redemption_RFC.txt"),
> Redemption:lRFC822); // this will trigger the unexpected exception
> if (FAILED(hr))
> {
> printf("Failed to save.");
> }
> pMailItem->Release();
> pItem->Release();
>
> ............. // other unrelated stuff.
>
>
> Thanks,
> -- Andy
>
> "Dmitry Streblechenko \(MVP\)" <dmitry@dimastr.com> wrote in message

news:<OG1v5#mUEHA.2972@TK2MSFTNGP12.phx.gbl>...
> > Did you make sure nativeFilename is valid?
> >
> > Dmitry Streblechenko (MVP)
> > http://www.dimastr.com/
> > OutlookSpy - Outlook, CDO
> > and MAPI Developer Tool
> >
> >
> > "andy" <gogowings@hotmail.com> wrote in message
> > news:a42d0bcf.0406140244.3c508517@posting.google.com...
> > > 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:lRFC822);
> > >
> > > if (isCopy == JNI_TRUE)
> > > {
> > > env->ReleaseStringChars(filename, nativeFilename);
> > > }
> > >
> > > /**** some other unrelated stuff ****/
> > > }



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off