C
Colin Thomsen
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 SetUnhandledExceptionFilter 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 UnhandledExceptionFilter 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(_Total)\\% Processor
Time" // % of cpu in use
LONG __stdcall SEHHandler(EXCEPTION_POINTERS *pExPtrs)
{
std::cout << "Caught the exception OK" << std::endl;
return (EXCEPTION_EXECUTE_HANDLER);
}
void exceptionTest()
{
SetUnhandledExceptionFilter(SEHHandler);
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_error("bad");
}
int main(int argc, char **argv)
{
exceptionTest();
return 0;
}
Any ideas?
(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 SetUnhandledExceptionFilter 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 UnhandledExceptionFilter 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(_Total)\\% Processor
Time" // % of cpu in use
LONG __stdcall SEHHandler(EXCEPTION_POINTERS *pExPtrs)
{
std::cout << "Caught the exception OK" << std::endl;
return (EXCEPTION_EXECUTE_HANDLER);
}
void exceptionTest()
{
SetUnhandledExceptionFilter(SEHHandler);
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_error("bad");
}
int main(int argc, char **argv)
{
exceptionTest();
return 0;
}
Any ideas?