473,829 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VC++, .NET and unhandled exceptions

I have a native VC++ application which runs differently
(incorrectly) if the .NET framework is installed.

A trimmed version of the app is shown below. The
intention is for the SEHHandler to catch any exceptions
which are not handled by the program. It is enabled using
the SetUnhandledExc eptionFilter call.

The Pdh calls are intended to add a counter to enable
retrieval of CPU usage (not included in this trimmed
version)

The problem seems to be that after the call to
PdhAddCounter, the UnhandledExcept ionFilter is reset. The
result is:
- without the call to PdhAddCounter, the program
prints 'Caught the exception OK'
- with the call to PdhAddCounter, the program quits with
a Windows dialog box

title: Microsoft Visual C++ Runtime Library
Message: Runtime Error!
Pogram: ...
This application has requested the Runtime to
terminate it in an unusual way. Please contact the
application's support team for more information.
This problem only occurs on computers with .NET installed.
#include <windows.h>
#include <stdexcept>
#include <pdh.h>
#include <tchar.h>
#include <iostream>

#define CNTR_CPU "\\Processor(_T otal)\\% Processor
Time" // % of cpu in use

LONG __stdcall SEHHandler(EXCE PTION_POINTERS *pExPtrs)
{
std::cout << "Caught the exception OK" << std::endl;
return (EXCEPTION_EXEC UTE_HANDLER);
}

void exceptionTest()
{
SetUnhandledExc eptionFilter(SE HHandler);
static HQUERY h;
static HCOUNTER hcounter;
PdhOpenQuery (0, 0, &h) ;
PDH_STATUS pdhStatus = PdhAddCounter (h,_T(CNTR_CPU) ,
0, &hcounter);
PdhCloseQuery (h);
throw std::runtime_er ror("bad");
}

int main(int argc, char **argv)
{
exceptionTest() ;
return 0;
}

Any ideas?

Nov 16 '05 #1
2 3270
That repros for me too - no idea why though. I'll ask someone from MS to
take a look.

-cd

Colin Thomsen wrote:
I have a native VC++ application which runs differently
(incorrectly) if the .NET framework is installed.

A trimmed version of the app is shown below. The
intention is for the SEHHandler to catch any exceptions
which are not handled by the program. It is enabled using
the SetUnhandledExc eptionFilter call.

The Pdh calls are intended to add a counter to enable
retrieval of CPU usage (not included in this trimmed
version)

The problem seems to be that after the call to
PdhAddCounter, the UnhandledExcept ionFilter is reset. The
result is:
- without the call to PdhAddCounter, the program
prints 'Caught the exception OK'
- with the call to PdhAddCounter, the program quits with
a Windows dialog box

title: Microsoft Visual C++ Runtime Library
Message: Runtime Error!
Pogram: ...
This application has requested the Runtime to
terminate it in an unusual way. Please contact the
application's support team for more information.
This problem only occurs on computers with .NET installed.
#include <windows.h>
#include <stdexcept>
#include <pdh.h>
#include <tchar.h>
#include <iostream>

#define CNTR_CPU "\\Processor(_T otal)\\% Processor
Time" // % of cpu in use

LONG __stdcall SEHHandler(EXCE PTION_POINTERS *pExPtrs)
{
std::cout << "Caught the exception OK" << std::endl;
return (EXCEPTION_EXEC UTE_HANDLER);
}

void exceptionTest()
{
SetUnhandledExc eptionFilter(SE HHandler);
static HQUERY h;
static HCOUNTER hcounter;
PdhOpenQuery (0, 0, &h) ;
PDH_STATUS pdhStatus = PdhAddCounter (h,_T(CNTR_CPU) ,
0, &hcounter);
PdhCloseQuery (h);
throw std::runtime_er ror("bad");
}

int main(int argc, char **argv)
{
exceptionTest() ;
return 0;
}

Any ideas?

Nov 16 '05 #2
I heard back from MS on this issue -

Apparently the phenomenon you're seeing is due to PDH DLL loading second
version of the CRT into the process, and the loading of the CRT causes the
unhandled exception filter to be reset. The variation in behavior from
machine to machine is reportedly due to different versions of PDH.DLL and/or
the CRT on those machines.

At present, it sounds like the only workaround is to be aware of the issue -
either make sure that PDH is loaded before you set the unhandled exception
filter, or call SetUnhandledExc eptionFilter again after using PDH functions.

This should be addressed in a future release.

-cd

Colin Thomsen wrote:
I have a native VC++ application which runs differently
(incorrectly) if the .NET framework is installed.

A trimmed version of the app is shown below. The
intention is for the SEHHandler to catch any exceptions
which are not handled by the program. It is enabled using
the SetUnhandledExc eptionFilter call.

The Pdh calls are intended to add a counter to enable
retrieval of CPU usage (not included in this trimmed
version)

The problem seems to be that after the call to
PdhAddCounter, the UnhandledExcept ionFilter is reset. The
result is:
- without the call to PdhAddCounter, the program
prints 'Caught the exception OK'
- with the call to PdhAddCounter, the program quits with
a Windows dialog box

title: Microsoft Visual C++ Runtime Library
Message: Runtime Error!
Pogram: ...
This application has requested the Runtime to
terminate it in an unusual way. Please contact the
application's support team for more information.
This problem only occurs on computers with .NET installed.
#include <windows.h>
#include <stdexcept>
#include <pdh.h>
#include <tchar.h>
#include <iostream>

#define CNTR_CPU "\\Processor(_T otal)\\% Processor
Time" // % of cpu in use

LONG __stdcall SEHHandler(EXCE PTION_POINTERS *pExPtrs)
{
std::cout << "Caught the exception OK" << std::endl;
return (EXCEPTION_EXEC UTE_HANDLER);
}

void exceptionTest()
{
SetUnhandledExc eptionFilter(SE HHandler);
static HQUERY h;
static HCOUNTER hcounter;
PdhOpenQuery (0, 0, &h) ;
PDH_STATUS pdhStatus = PdhAddCounter (h,_T(CNTR_CPU) ,
0, &hcounter);
PdhCloseQuery (h);
throw std::runtime_er ror("bad");
}

int main(int argc, char **argv)
{
exceptionTest() ;
return 0;
}

Any ideas?

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2281
by: terry | last post by:
Hi, Question: When using Framesets and Server.Transfer in the Application_Error event handler is there a mechanism to get the error page to display in the total view of the browser not just in the offending frame? Overview: I have an application in which I am using framesets. When an Unhandled exception occurs I try to handle it
4
2411
by: Frank | last post by:
Hi, I made a handler for unhandled errors. But before that is executed, VB.NET gives me the standard error window. In VB6 there was a setting (errortrapping) about handling errors in the design environment and classes, which should prevent the before mentioned behaviour. Does VB.NET have a setting like it? Or is there something else? Thanks in advance Frank
5
5757
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by thread.Abort()) is reported twice: once in the debug window, and once through the message box. Is it because the thread was sleeping when the exception occurred?
5
3316
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can view it in one of the windows (autos or locals, don't remember which). That doesn't appear to be the case with vb.net. I also tried using the command window to inspect "Err" but that gave nothing useful (always empty).
5
4546
by: Sam Loveridge | last post by:
Hi All. I'm hoping someone can point me in the direction of a solution to unhandled exceptions in MDI child forms causing the application to crash. I've found various articles describing a method using Application.Run(new MyMainParentForm) to place in the application's Sub Main to allow catching of unhandled exceptions in the application. The problem I'm facing is that I want to be able to trap unhandled exceptions at the MDI child...
0
1993
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks about in a new application I'm writing. However, when I try to use ThreadStart to do some work in a separate thread from my GUI, the methods Jason described don't seem to catch the exception. Take the following source code: Public Class...
2
2187
by: Bob | last post by:
I MUST be able to trap unhandled exceptions, bring the thread to a routine that then closes the thread on which the execption occurred without closing or affecting the other threads. Think of an Interactive voice response telephone application. An unforeseen error occurs on one phone call. You terminate that phone call politely but you don't all of a sudden hang up the phone without warning on the other 400 callers that are on line at that...
3
1959
by: Andreas van de Sand | last post by:
Hi everyone, I've got an application which uses a custom exception handler and to avoid unhandled exceptions I've got a try{}catch (Exception){} block around the main Application.Run(...). Works all good on my machine, whenever something unexpected happens the exception get caught, logged and it shows a nicer message. Unfortunately for some reason, this only works on my machine! If i deploy my project to some other computer I get the...
20
11491
by: joseph_gallagher | last post by:
Hi, I've recently ported a .Net 1.1 application to .Net 2.0 and the one new feature that is getting on my nerves is that when there is an unhandled exception the application completely crashes, causing user to loose all the work they have done where they could previously just click continue and in 99% of cases be fine. Is there an option to turn this annoying crash and loose everything option off, I can see it has its merits but in my...
0
9775
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9632
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10472
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10191
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7732
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5614
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5771
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3951
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.