tags:

views:

103

answers:

2

I have an unmanaged c++ application that provides a custom _matherr handler. When this application loads and runs code in unmanaged DLLs, if there is a Math error ( e.g. asin( 100.0 ) ) the custom _matherr function is called and everything works.

However, I'm now trying to create a NUnit Test DLL in C++/CLI that loads the same unmanaged DLL and runs the same code as the application above. What I want to do is add the _matherr function to the C++/CLI dll such that when math errors occur I can perform some custom handler logic.

The C++/CLI dll compiles just fine with the _matherr function defined, but when I force a math error from the unmanaged dll, the _matherr function is not called.

Is this not supported by C++/CLI? The MSDN documentation seems to say _matherr is supported by all C Run times, (with a link to a list of runtimes including the /clr runtime. )

A: 

Maybe you need something like a proxy dll, passing through each function call to the original dll excepting those you want to be handled extra.

macs
+2  A: 

My experience is that defining _matherr does not work if done in a dll. It must be defined in the executable.

I've even seen compilers that when you try to add _matherr in a dll, will not link it in because they don't see anybody making a reference to it.

broc