![]() |
|
Crash in GetMAPIOBJECT + Outlook 2007
Hi,
I'm using the following code to get the IMAPIProp-Pointer to the current Outlook mail window. Worked nicely so far. But when I'm testing it with Outlook 2007 beta, the GetMAPIOBJECT call causes an exception. If I perform the same steps as the program below does with OutlookSpy and Outlook 2007 everything works nicely - so what am I doing wrong, here? I'd be grateful for any ideas... THANKS! pete Outlook::_InspectorPtr spInspector = m_OLAppPtr-ActiveWindow(); if (spInspector) { IDispatch *pd = spInspector-GetCurrentItem(); if (pd) { Outlook::_MailItem *pMailItem = NULL; const GUID local_IID_IMailItem = {0x00063034,0,0, {0xC0,0,0,0,0,0,0,0x46}}; pd-QueryInterface (local_IID_IMailItem, (LPVOID *)&pMailItem); if (pMailItem) { IUnknown *iu = pMailItem-GetMAPIOBJECT(); //Crashes in Outlook 2007 Beta ..... |
Crash in GetMAPIOBJECT + Outlook 2007
Where is your code running? Is it in the outook.exe process space (your code
is a COM add-in) or in a separate exe? Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "pete_42" wrote in message ups.com... Hi, I'm using the following code to get the IMAPIProp-Pointer to the current Outlook mail window. Worked nicely so far. But when I'm testing it with Outlook 2007 beta, the GetMAPIOBJECT call causes an exception. If I perform the same steps as the program below does with OutlookSpy and Outlook 2007 everything works nicely - so what am I doing wrong, here? I'd be grateful for any ideas... THANKS! pete Outlook::_InspectorPtr spInspector = m_OLAppPtr-ActiveWindow(); if (spInspector) { IDispatch *pd = spInspector-GetCurrentItem(); if (pd) { Outlook::_MailItem *pMailItem = NULL; const GUID local_IID_IMailItem = {0x00063034,0,0, {0xC0,0,0,0,0,0,0,0x46}}; pd-QueryInterface (local_IID_IMailItem, (LPVOID *)&pMailItem); if (pMailItem) { IUnknown *iu = pMailItem-GetMAPIOBJECT(); //Crashes in Outlook 2007 Beta .... |
Crash in GetMAPIOBJECT + Outlook 2007
Dmitry Streblechenko wrote:
Where is your code running? Is it in the outook.exe process space (your code is a COM add-in) or in a separate exe? It's an add-in. |
Crash in GetMAPIOBJECT + Outlook 2007
Hmmm... What kind of exception is it? A COM error or something like an
access violation? Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "pete_42" wrote in message oups.com... Dmitry Streblechenko wrote: Where is your code running? Is it in the outook.exe process space (your code is a COM add-in) or in a separate exe? It's an add-in. |
Crash in GetMAPIOBJECT + Outlook 2007
Dmitry Streblechenko wrote:
Hmmm... What kind of exception is it? A COM error or something like an access violation? Good question. I tried 3 catch'es: catch(_com_error &) catch (CException *) catch (...) The third one caught the exception. So it's probably an access violation. Can the pointer be wrong? Am I doing a bad cast somehow?? |
Crash in GetMAPIOBJECT + Outlook 2007
What happens when you run your code under the debugger? Did you set "break
on exception" for all exceptions in Debug | Exceptions dialog? Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "pete_42" wrote in message ups.com... Dmitry Streblechenko wrote: Hmmm... What kind of exception is it? A COM error or something like an access violation? Good question. I tried 3 catch'es: catch(_com_error &) catch (CException *) catch (...) The third one caught the exception. So it's probably an access violation. Can the pointer be wrong? Am I doing a bad cast somehow?? |
Crash in GetMAPIOBJECT + Outlook 2007
Took some time, but I got some news:
1. pMailItem-Save(); Works most of the time. (Currently I don't worry about RARE crashes) 2. pMailItem-get_MAPIOBJECT(...); Works most of the time, about always yields a NULL pointer. 3. pMailItem-get_Class(...) Works most of the time and yields 43. = So the pMailItem Pointer should be correct. If I compile my DLL in debug mode (Previously I used release mode for an easier deployment on the other PC), I get an error messagesaying the ESP wasn't properly restored, probably because of differing calling coventions. So I guess that my include files (Generated from Outlook 2000) are bad. Quoting from msoutl9.tlh: __declspec(property(get=GetMAPIOBJECT)) IUnknownPtr MAPIOBJECT; and virtual HRESULT __stdcall get_MAPIOBJECT ( IUnknown * * MAPIOBJECT ) = 0; Quoting from msoutl9.tli: #pragma implementation_key(564) inline IUnknownPtr Outlook::_MailItem::GetMAPIOBJECT ( ) { IUnknown * _result; HRESULT _hr = get_MAPIOBJECT(&_result); if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this)); return IUnknownPtr(_result, false); } But this yields new questions: - Does GetMAPIOBJECT really call get_MAPIOBJECT? If so, why don't I get a crash for the latter and why does Microsoft recommend no to use get_MAPIOBJECT? - Is the include bad? And how? Is _stdcall or HRESULT or IUnknown defined wrong by some include? - Is there another way to call the function? Some generic Invoke/Message/Whatever? - Which call do you perform in OutlookSpy when I doubleclick the MAPIOBJECT item in the CurrentItem() View? Thanks. Dmitry Streblechenko wrote: What happens when you run your code under the debugger? Did you set "break on exception" for all exceptions in Debug | Exceptions dialog? |
Crash in GetMAPIOBJECT + Outlook 2007
Don't know about the headers - I don't use VC++. Did you try to create new
headers using the Outlook 2007 type library? OutlookSpy always uses late binding when retrieving that property - call IDispatch::GetIDsOfNames("MAPIOBJECT", ...) then IDispatch::Invoke(). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "pete_42" wrote in message ups.com... Took some time, but I got some news: 1. pMailItem-Save(); Works most of the time. (Currently I don't worry about RARE crashes) 2. pMailItem-get_MAPIOBJECT(...); Works most of the time, about always yields a NULL pointer. 3. pMailItem-get_Class(...) Works most of the time and yields 43. = So the pMailItem Pointer should be correct. If I compile my DLL in debug mode (Previously I used release mode for an easier deployment on the other PC), I get an error messagesaying the ESP wasn't properly restored, probably because of differing calling coventions. So I guess that my include files (Generated from Outlook 2000) are bad. Quoting from msoutl9.tlh: __declspec(property(get=GetMAPIOBJECT)) IUnknownPtr MAPIOBJECT; and virtual HRESULT __stdcall get_MAPIOBJECT ( IUnknown * * MAPIOBJECT ) = 0; Quoting from msoutl9.tli: #pragma implementation_key(564) inline IUnknownPtr Outlook::_MailItem::GetMAPIOBJECT ( ) { IUnknown * _result; HRESULT _hr = get_MAPIOBJECT(&_result); if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this)); return IUnknownPtr(_result, false); } But this yields new questions: - Does GetMAPIOBJECT really call get_MAPIOBJECT? If so, why don't I get a crash for the latter and why does Microsoft recommend no to use get_MAPIOBJECT? - Is the include bad? And how? Is _stdcall or HRESULT or IUnknown defined wrong by some include? - Is there another way to call the function? Some generic Invoke/Message/Whatever? - Which call do you perform in OutlookSpy when I doubleclick the MAPIOBJECT item in the CurrentItem() View? Thanks. Dmitry Streblechenko wrote: What happens when you run your code under the debugger? Did you set "break on exception" for all exceptions in Debug | Exceptions dialog? |
Crash in GetMAPIOBJECT + Outlook 2007
YESYESYES!!!!! :)
Now it works. If I Invoke() the call manually it works. But now I found a different problem. :( Once I Save an unsaved mail, the "pMailItem" seems to become bad. I can't pMailItem-Release it. Or Invoke Save again. Both causes a crash. Does the Save invalidate the pMailItem? Don't I have to release it? Or do I have to wait for the Save to finish? Somehow... |
Crash in GetMAPIOBJECT + Outlook 2007
I have never seen or heard about such a problem with MailItem.Save.
I strongly suspect that something happens in your code :-) Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "pete_42" wrote in message oups.com... YESYESYES!!!!! :) Now it works. If I Invoke() the call manually it works. But now I found a different problem. :( Once I Save an unsaved mail, the "pMailItem" seems to become bad. I can\'t pMailItem-Release it. Or Invoke Save again. Both causes a crash. Does the Save invalidate the pMailItem? Don\'t I have to release it? Or do I have to wait for the Save to finish? Somehow... |
All times are GMT +1. The time now is 01:00 PM. |
|
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com