SetUnhandledExceptionFilter in Office Addin

M

Mark Wilson

Is it possible to setup a custom unhandled exception handler in an Office
2007 addin?

I have an Outlook Exchange Client Extension and have added some code in the
IOutlookExtItemEvents::OnOpen method. Its sets up an exception handler and
then forces an exception. However, the exception handler never seems to get
called because the standard Windows Vista dialog pops up indicating that an
exception occurred.

Sample code is as follows:

STDMETHODIMP MyOutlookExtItemEvents::OnOpen(LPEXCHEXTCALLBACK lpeecb)
{
Crash();
return S_FALSE;
}

void Crash(void)
{
int nAnswer = MessageBox(GetFocus(), "Crash this program?", "OnOpen Test",
MB_ICONEXCLAMATION | MB_YESNO);
if (nAnswer == IDYES)
{
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
int* ptr = 0;
*ptr = 0;
}
return;
}

LONG WINAPI MyUnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
{
MessageBox(GetFocus(),"EXCEPTION_CONTINUE_SEARCH", "OnOpen Test", MB_OK);
return EXCEPTION_CONTINUE_SEARCH;
}

I know that the crash and exception filter work because I can create a
console application that loads the DLL with LoadLibrary and calls Crash() by
using GetProcAddress. In that case, the message "EXCEPTION_CONTINUE_SEARCH"
displays before the Windows Vista exception dialog.
 
S

SvenC

Hi Mark,
Is it possible to setup a custom unhandled exception handler in an Office
2007 addin?

I have an Outlook Exchange Client Extension and have added some code in
the
IOutlookExtItemEvents::OnOpen method. Its sets up an exception handler
and
then forces an exception. However, the exception handler never seems to
get
called because the standard Windows Vista dialog pops up indicating that
an
exception occurred.

Check these articles:

http://www.debuginfo.com/articles/debugfilters.html#enforce
http://blog.kalmbachnet.de/?postid=75
 
M

Mark Wilson

Thanks Sven.

I already looked at those and tried the proposed solution but my filter
never gets called. I can see that it would be very useful to set a filter
now and have it persist for quite some time until an exception occurred.
However, I’m setting a filter and forcing a crash two lines of code later. I
don’t think it’s likely that someone else has detached my filter in that
short period of time. This code works fine on Outlook XP with Outlook 2003.
If I can get the filter to initially work, then I can try to make it persist.
 
S

SvenC

Hi Mark,
I already looked at those and tried the proposed solution but my filter
never gets called.

Did you try to set the filter earlier, e.g. in you addins OnConnect function
or even earlier in DllMain?

Maybe someone else is using the same technique to "disable" later
SetUnhandlerExceptionFilter calls.
 
M

Mark Wilson

Hi Sven.

I did try it in DLLMain for DLL_PROCESS_ATTACH and the filter still didn't
work.

Additional testing reveals the sample code above works as follows:

Windows XP/Outlook 2000 [Filter works]
Windows XP/Outlook XP [Filter works]
Windows XP/Outlook 2003 [Filter works]
Windows Vista/Outlook 2003 [Filter works]
Windows XP/Outlook 2007 [Filter fails to trap exception]
Windows Vista/Outlook 2007 [Filter fails to trap exception]

So I assume Outlook 2007 is not permitting this hander to be installed.

If someone other than Microsoft has set a filter and locked it down then I'm
assuming a crash would go to their filter. However, I'm getting the standard
Windows error report dialog in Windows XP and Windows Vista when the addin is
running under Outlook 2007.
 
J

Jie Wang [MSFT]

Hello Mark,

The behavior you observed is by design.

3rd-party addins/dlls cannot set the unhandled exception filter for Office
2007 apps (at least not in a supported way). MSO.DLL explicitly sets the
filter itself, then overrides the API to prevent 3rd-parties for changing
the filter after MSO has set it. It is common to all the Office apps (not
just Outlook).

It should be noted that the new behavior makes the apps more consistent.
Some Office apps have threads that will trap exceptions at their base and
raise Watson directly, so addins/dlls that rely on the unhandled filter can
miss entire events and/or make the CER data picture skewed. So the new
behavior enforces consistency -- everything goes to watson, or everything
goes to debugger, so either has more complete picture of the problem(s) and
doesn't miss events.

If you want to collect crash data from your clients, here is another
possible solution:

Microsoft actually runs a service for third-party developers to get access
to their error reporting issues. You may want to visit
https://winqual.microsoft.com/default.aspx, where you can register your
add-in name and versions and get access to the CAB files for your errors.
This is the supported methodology.

If you have any further questions regarding this issue, please feel free to
post here.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Thanks for the explanation Jie.

I've just finished reading a lot of info on WER from the URL you sent me.
For systems with access to the Internet, it looks like a very useful
solution. However in this situation my users are on networks that are
isolated from the Internet and thus have no connectivity to Microsoft. I'm
looking for a solution that would allow the user to provide me a crash
address and at an offset into a DLL.

If I could create my own handler, then I could write a few lines of text to
a file that the user could read with Notepad.exe and print. The info could
be faxed or read over the phone.

When an application crashes and WER brings up its dialog, what happens if
there is no connection to Microsoft? Can any of the crash data be saved on
the workstation?

For example can it force a MiniDump file to be created?

--
Mark Wilson



"Jie Wang [MSFT]" said:
Hello Mark,

The behavior you observed is by design.

3rd-party addins/dlls cannot set the unhandled exception filter for Office
2007 apps (at least not in a supported way). MSO.DLL explicitly sets the
filter itself, then overrides the API to prevent 3rd-parties for changing
the filter after MSO has set it. It is common to all the Office apps (not
just Outlook).

It should be noted that the new behavior makes the apps more consistent.
Some Office apps have threads that will trap exceptions at their base and
raise Watson directly, so addins/dlls that rely on the unhandled filter can
miss entire events and/or make the CER data picture skewed. So the new
behavior enforces consistency -- everything goes to watson, or everything
goes to debugger, so either has more complete picture of the problem(s) and
doesn't miss events.

If you want to collect crash data from your clients, here is another
possible solution:

Microsoft actually runs a service for third-party developers to get access
to their error reporting issues. You may want to visit
https://winqual.microsoft.com/default.aspx, where you can register your
add-in name and versions and get access to the CAB files for your errors.
This is the supported methodology.

If you have any further questions regarding this issue, please feel free to
post here.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Hi Jie.

I think a poartial solution would be to determine the OS version and Office
version.

For Office 2003 or older I can use SetUnhandledExceptionFilter to call code
that creates a MiniDump.

If it is Office 2007 and the OS is Vista SP1 or Windows Server 2008 I can
force a MiniDump automatically at crash time with a registry setting
http://msdn.microsoft.com/en-us/library/bb787181(VS.85).aspx

If it is Office 2007 with Vista RTM or Office 2007 on Windows XP, I guess
I'm stuck.

--
Mark Wilson



"Jie Wang [MSFT]" said:
Hello Mark,

The behavior you observed is by design.

3rd-party addins/dlls cannot set the unhandled exception filter for Office
2007 apps (at least not in a supported way). MSO.DLL explicitly sets the
filter itself, then overrides the API to prevent 3rd-parties for changing
the filter after MSO has set it. It is common to all the Office apps (not
just Outlook).

It should be noted that the new behavior makes the apps more consistent.
Some Office apps have threads that will trap exceptions at their base and
raise Watson directly, so addins/dlls that rely on the unhandled filter can
miss entire events and/or make the CER data picture skewed. So the new
behavior enforces consistency -- everything goes to watson, or everything
goes to debugger, so either has more complete picture of the problem(s) and
doesn't miss events.

If you want to collect crash data from your clients, here is another
possible solution:

Microsoft actually runs a service for third-party developers to get access
to their error reporting issues. You may want to visit
https://winqual.microsoft.com/default.aspx, where you can register your
add-in name and versions and get access to the CAB files for your errors.
This is the supported methodology.

If you have any further questions regarding this issue, please feel free to
post here.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jie Wang [MSFT]

Hi Mark,

Not sure if your users are in a corp network, if that was the case, there
could be another option for crash data collection.

Corporate Error Reporting (CER) is a Microsoft tool that allows companies
to capture information from applications that are Windows Error Reporting
(WER) enabled.

CER provides companies with several benefits. Many companies do not want
their users to automatically forward crash data to Microsoft due to
concerns of forwarding company confidential information. CER allows
administrators to control crash data before it is forwarded to Microsoft.

If that sounds like that you want, you can take a look at this document and
see if it is possible to deploy CER as a better solution:

http://download.microsoft.com/download/5/9/2/592d2308-a6a2-48ad-ae8f-72f888b
9d361/CER_Implementation_Plan.pdf

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Jie, can you confirm that Outlook 2007 blocks the creation of user-mode
minidumps?

I have my Vista SP1 systems configured to create user-mode minidumps when an
application crashes.

I'm using SysInternals ProcessMonitor to watch the WER registry keys. On a
normal crash I see werfault.exe access registry keys at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error
Reporting\LocalDumps and it creates a crash file in the configured folder
with the application name in the dump file name.

When and Outlook 2003 addin on Vista/SP1 crashes it runs werfault.exe and
created a dump called SearchProtocolHost.exe.nnnn.dmp

When an Outlook 2007 addin on Vista/SP1 crashes, werfault.exe does not
execute and the registry keys at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error
Reporting\LocalDumps are never read.

Is this by design?


--
Mark Wilson



"Jie Wang [MSFT]" said:
Hello Mark,

The behavior you observed is by design.

3rd-party addins/dlls cannot set the unhandled exception filter for Office
2007 apps (at least not in a supported way). MSO.DLL explicitly sets the
filter itself, then overrides the API to prevent 3rd-parties for changing
the filter after MSO has set it. It is common to all the Office apps (not
just Outlook).

It should be noted that the new behavior makes the apps more consistent.
Some Office apps have threads that will trap exceptions at their base and
raise Watson directly, so addins/dlls that rely on the unhandled filter can
miss entire events and/or make the CER data picture skewed. So the new
behavior enforces consistency -- everything goes to watson, or everything
goes to debugger, so either has more complete picture of the problem(s) and
doesn't miss events.

If you want to collect crash data from your clients, here is another
possible solution:

Microsoft actually runs a service for third-party developers to get access
to their error reporting issues. You may want to visit
https://winqual.microsoft.com/default.aspx, where you can register your
add-in name and versions and get access to the CAB files for your errors.
This is the supported methodology.

If you have any further questions regarding this issue, please feel free to
post here.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jie Wang [MSFT]

Hi Mark,

Just a quick note, I'll check it and get back to you.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jie Wang [MSFT]

Hi Mark,

Sorry for the late reply. I was trying to get more info from the product
team but not getting any reply yet.

I did some tests to crash my Outlook 2007 in several ways, the WER is
always launched on my side.

You may want to try setting the following reg key to value 1:

HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error
Reporting\ForceQueue

This will force the dump to be generated and included in the report. As
described in the following articles:

Windows Error Reporting (WER) for developers
http://blogs.msdn.com/oanapl/archive/2009/01/28/windows-error-reporting-wer-
for-developers.aspx

WER Settings
http://msdn.microsoft.com/en-us/library/bb513638(VS.85).aspx

I'll try to find out more about this topic, however, since you already
know, this news group is focusing on Office COM Add-in development,
configuring WER is beyond my specialties. So I suggest you goto Microsoft
TechNet forum and looking for help on configuring WER:
http://social.technet.microsoft.com/Forums/en/categories. There're many IT
experts know much more about WER than I do.

I'll keep monitoring this issue and if there is anything I can do for you,
please don't hesitate to let me know.

Best regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Thanks Jie.

I know that WER is outside the scope of this forum and if your system can
create a dump, then the action must not be blocked by Office. I'll try your
suggestions and see what happens.

Regards.
--
Mark Wilson



"Jie Wang [MSFT]" said:
Hi Mark,

Sorry for the late reply. I was trying to get more info from the product
team but not getting any reply yet.

I did some tests to crash my Outlook 2007 in several ways, the WER is
always launched on my side.

You may want to try setting the following reg key to value 1:

HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error
Reporting\ForceQueue

This will force the dump to be generated and included in the report. As
described in the following articles:

Windows Error Reporting (WER) for developers
http://blogs.msdn.com/oanapl/archive/2009/01/28/windows-error-reporting-wer-
for-developers.aspx

WER Settings
http://msdn.microsoft.com/en-us/library/bb513638(VS.85).aspx

I'll try to find out more about this topic, however, since you already
know, this news group is focusing on Office COM Add-in development,
configuring WER is beyond my specialties. So I suggest you goto Microsoft
TechNet forum and looking for help on configuring WER:
http://social.technet.microsoft.com/Forums/en/categories. There're many IT
experts know much more about WER than I do.

I'll keep monitoring this issue and if there is anything I can do for you,
please don't hesitate to let me know.

Best regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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