FPU Control Word Nightmare - PLEASE HELP


2004-12-14 10:22:42 AM
cppbuilder34
Hi (posted previously in ActiveX group - I have more info now - reposting
here),
My COM server works well - but I found that some clients using it in C# had
bizarre problems which initially seemed unrelated.
After more investigation, I discovered that the .NET RTL expects all
exceptions to be masked, and that somehow when my component was created the
FPU control word was changed. I was able to reproduce this. I added a
routine to the end of my constructor and calls inside the COM server like
this:
SetExceptionMask(TFPUExceptionMask() << exInvalidOp
<< exDenormalized << exZeroDivide << exOverflow
<< exUnderflow << exPrecision);
This effectively masks all exceptions. Now the C# code all works exactly
like expected. (no problem). BUT THIS IS SUPER DANGEROUS. Other clients of
my COM server might need a different control word and this will cause
undefined results in my clients programs.
I tried getting the current control word inside the COM server in both my
constructor and inside DllEntryPoint() with good intentions to restore it
later - but for some reason by the time either of these functions is
called - it is already changed! So, I have no way of finding what the
control word was before my COM server was invoked!
Is there any way for me to get, change and the *restore* the control word
from inside my COM server?
BCB6 patched.
TIA.
M.