2

i trying to call a COM-Object which is described here

Is it possible to package WPF window as COM Object

from a Delphi App.

After importing the tlb, i'm using this code to call that COM Object.

var
  y: ITestWpfInterface;
begin
  y:=CreateComObject(CLASS_TestWpfInterface) as ITestWpfInterface;
  y.TestWpf();
end;

the COM Object gets instantiated and the method is called. but the COM Objects crashes the Delphi app, when it is reaching the

Window1 form = new Window1();

line. when i'm trying to do the same from word-VBA the wpf windows is show.

Sub test()
  Dim x As New WpfControlLibrary1.TestWpfInterface
  x.TestWpf
End Sub

catch blocks around the new window does not show any exceptions. i have debugged the application with windbg. it shows me a div by 0 exception, after loading the framework wpf assembly's

why does the delphi app crash? what causes the crash. how to solve it?

edit: this is the output from windbg

ModLoad: 76330000 7634d000   C:\WINDOWS\system32\IMM32.DLL
ModLoad: 5b0f0000 5b128000   c:\windows\system32\uxtheme.dll
ModLoad: 75250000 7527e000   C:\WINDOWS\system32\msctfime.ime
ModLoad: 76f90000 7700f000   C:\WINDOWS\system32\CLBCATQ.DLL
ModLoad: 77010000 770e3000   C:\WINDOWS\system32\COMRes.dll
ModLoad: 79000000 7904a000   C:\WINDOWS\system32\mscoree.dll
ModLoad: 603b0000 60417000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll
ModLoad: 76970000 76a21000   C:\WINDOWS\system32\sxs.dll
ModLoad: 79140000 797ae000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
ModLoad: 79060000 7911e000   C:\WINDOWS\system32\MSVCR100_CLR0400.dll
ModLoad: 77f40000 77fb6000   C:\WINDOWS\system32\SHLWAPI.dll
(2b4.244): Unknown exception - code 04242420 (first chance)
ModLoad: 79880000 7a641000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\mscorlib\a774bd593b8420bae4a8cf1d46af3ba2\mscorlib.ni.dll
ModLoad: 60340000 6034d000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\culture.dll
ModLoad: 60930000 60940000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll
ModLoad: 03270000 03549000   C:\WINDOWS\system32\xpsp2res.dll
ModLoad: 79810000 79870000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clrjit.dll
ModLoad: 7a830000 7b0dd000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\System\5286fe2d0167eb835a9f11025f1cb756\System.ni.dll
ModLoad: 58c20000 58fd1000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\WindowsBase\9dacf8a5033dfbcb435be166d2f42cdf\WindowsBase.ni.dll
ModLoad: 68000000 68036000   C:\WINDOWS\system32\rsaenh.dll
ModLoad: 55590000 5607d000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\PresentationCore\8244412387a82c0acd3d63622e22cef5\PresentationCore.ni.dll
ModLoad: 56980000 57aad000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\PresentationFramewo#\813a0913bea1269e48613509609e72b4\PresentationFramework.ni.dll
ModLoad: 561c0000 562a1000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\WPF\wpftxt_v0400.dll
ModLoad: 55000000 5519a000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\WPF\wpfgfx_v0400.dll
ModLoad: 554c0000 55585000   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationNative_v0400.dll
ModLoad: 59200000 593b5000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\System.Xaml\a3ffdc1316821b5ceb32c9a788334329\System.Xaml.ni.dll
ModLoad: 60c90000 60d83000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\System.Configuration\4844dd28e0611d1ebd1e449fe822c2a5\System.Configuration.ni.dll
ModLoad: 69760000 69cbe000   C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\System.Xml\419103071a5a5d17738afbe9dd03d58a\System.Xml.ni.dll
(2b4.244): Unknown exception - code c0000090 (first chance)
(2b4.244): Unknown exception - code c0000090 (first chance)
(2b4.244): Unknown exception - code c0000090 (first chance)
eax=000000c0 ebx=00007530 ecx=001b1e30 edx=00000020 esi=00000000 edi=0374ff50
eip=7c91e514 esp=0374ff20 ebp=0374ff78 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000206
ntdll!KiFastSystemCallRet:
7c91e514 c3              ret

a German version of this question inclusive sample code can found here: http://www.delphipraxis.net/166199-com-interop-mit-einer-c-library-mit-wpf-und-com.html

3
  • did you try to import the COM object as a component in delphi? Commented Feb 2, 2012 at 13:35
  • i tried both early and late bindings. both crashes that app. crash = instant close of the delphi app. Commented Feb 2, 2012 at 13:58
  • without register the com object with regasm it is not possible to get an instance of the object. regasm is also used to generate the tlb. this tlb is imported into delphi. everything is fine, except dotnet is creating the wpf window. Commented Feb 3, 2012 at 15:01

2 Answers 2

2

delphi doesn't mask the exception from the wpf which are raised in the fpu.

by setting a exception mask, the fpu ignores these exceptions.

SetExceptionMask(
    [exInvalidOp, exDenormalized, exZeroDivide, 
    exOverflow, exUnderflow, exPrecision]
);

this function is located in the math unit.

http://docwiki.embarcadero.com/VCL/en/Math.SetExceptionMask

thanks goes to Bernhard Geyer, who had this idea.

Sign up to request clarification or add additional context in comments.

Comments

1

I have been debugging a strange issue while developing a plugin DLL for another application for several months until I found out that this was the issue. The DLL was running fine for years, until we got a Win 22h2 .Net update (clr.dll 4.8 and above) and it would crash the host process. (Citect32.exe)

I simply added the following lines to my initialization code and it worked!

#include <System.Math.hpp>
SetExceptionMask(exAllArithmeticExceptions);

It was a particularly hard issue because the application crashed outside of the plugin code. It looked like our plugin was not doing anything strange, but when linking without the Delphi RTL dependencies or by loading the plugins in a different order, the problem disappeared. We were even considering re-writing the whole thing in MsVS because we were suspecting it had something to do with the Embarcadero RAD Studio 11 environment.

It turns out that the Delphi RTL had poisoned the Control Word 8087 when loading and setting up the DLL dependencies, in a way that was invisible to the developers of the Host program or the Plugin. I hope this article gets found by others, I got here through a chinese copy of this article on codenong. These are the error codes from the debugger that I got:

(3070.3ea4): Unknown exception - code c0000090 (first chance)
(... 600x repeats of this until)
(3070.3ea4): Stack overflow - code c00000fd (first chance)

Anyway, thanks again to Bernhard Geyer!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.