Wrong exception after calling .net4.0 com server from delphi application -


we migrating our codebase bds2006 rad studio xe, , found strange behavior: if make invalid floating point operation (ie. division zero) after creating object com server implemented in .net4.0, don't normal exception (ie. edivisionbyzero), estackoverflow.

we managed prepare simple example: comerrorexample

there .net 4.0 assembly, com interface (one function returning string) , simple delphi application:

var   a, b: double;   stored8087cw: word;  begin   coinitialize(nil);    try     b := 0;     := 1 / b;   except     on e: exception       writeln(e.classname, ': ', e.message, ' (expected type of exception)');   end;    stored8087cw := get8087cw;   writeln('code .net com: ', coexampleofcom.create.dosomething);   set8087cw(stored8087cw); //it's show 8087 control word doesn't change    try     b := 0;     := 1 / b;   except     on e: exception       writeln(e.classname, ': ', e.message, ' (unexpected type of exception! why stack overflow?)');   end;    readln;    couninitialize;  end. 

as can see, make 2 divisions 0 - first one, before com object creation, throws edivisionbyzero, second 1 throws estackoverflow.

we tested on win7 x64, , winxp x32 - no difference. when switched com server .net4.0 .net3.5 - works fine.

question: doing wrong? can fix problem?

switching .net3.5, or dumping delphi isn't option us.

update: checked floating point configuration ( set8087cw() ) before without luck. update2: i've expanded example restoring floating point configuration.

it looks in com dll changing floating point processor configuration. see default8087cw , set8087cw in delphi help.

you can save before doing com dll , restore afterwards.

var   saved8087cw: word; begin   saved8087cw := default8087cw;   // if want, disable fpu exceptions    // next line.   set8087cw($133f);   doyourcomoperationhere;   set8087cw(saved8087cw); end; 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -