从delphi2006调用.net dll来显示wpf表单

我正在使用Robert Gieseckes伟大的Unmanaged Exports从Delphi2006调用ac#-Dll。 如果我使用输入和输出的简单过程和函数,一切都很好。 但现在我想通过调用OpenMyWindow()显示一个Wpf-Window。 在这里,我得到一个“外部例外E0434352”。 我不知道为什么这不起作用。 无论如何,我认为这与wpf方面的初始化有关。

这是Delphi代码:

unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls; type TForm2 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; procedure OpenMyWindow(); stdcall; external 'ClassLibraryToDelphi.dll'; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin OpenMyWindow(); end; end. 

现在是c#部分(它是一个将UserControl改为窗口的ClassLibrary):

 using System.Linq; using System.Runtime.InteropServices; using RGiesecke.DllExport; namespace ClassLibraryToDelphi { public static class Test { private static UserControl1 myWindow; [DllExport] public static void OpenMyWindow() { myWindow = new UserControl1(); myWindow.ShowDialog(); } } } 

这是xaml:

    

和Codebehind:

 using System.Windows; namespace ClassLibraryToDelphi { public partial class UserControl1 : Window { public UserControl1() { InitializeComponent(); } } } 

我认为复制没什么特别或太复杂。

如果罗伯特看到这个问题(任何其他答案也得到赞赏)会很棒。

谢谢

这样做很简单。 在Project-Options的Build-Tab下,你必须选择’Register for COM interop’,在Signing下你必须输入一个强名称。 比你得到你的DLL的tlb文件。 在Delphi中,您必须转到“组件导入”并将tlb文件添加到项目中。 在dpr文件中,您必须添加Set8087CW($ 133F)bevor Application.Initialize以禁用浮点exception。

而已!

根据user3016412的回答,我试图添加Set8087CW($ 133F)程序调用。 这对我来说已经足够了。