从调用一个delphi2006 NET的DLL来显示WPF窗体 [英] Calling a .net dll from delphi2006 to show a wpf form

查看:393
本文介绍了从调用一个delphi2006 NET的DLL来显示WPF窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是罗伯特·Gieseckes很大托管输出调用从Delphi2006一个C#-Dll。一切运作良好,如果我用简单的过程和函数与输入和输出。
但现在我想通过调用OpenMyWindow显示一个WPF的窗口()。
在这里,我得到一个外部异常E0434352。
我不知道为什么,这是行不通的。 。无论如何,我认为这是与初始化在WPF方



下面是Delphi代码:



<预类=郎帕斯卡prettyprint-覆盖> 单元UNIT2;

接口

使用
的Windows,信息,SysUtils单元,变体,类图形,控件,窗体,对话框,菜单,StdCtrls中;


TForm2 =类(TForm的)
Button1的:TButton的;
过程Button1Click(发件人:TObject的);
端;


程序OpenMyWindow(); STDCALL;外部ClassLibraryToDelphi.dll';

变种
窗体2:TForm2;

实施

{$ R * .DFM}

过程TForm2.Button1Click(发件人:TObject的);
开始
OpenMyWindow();
端;

端。

和现在的C#的部分(这是与用户控件一个ClassLibrary改为窗口):



<预类=郎-CS prettyprint-覆盖> 使用System.Linq的;使用System.Runtime.InteropServices
;
使用RGiesecke.DllExport;

命名空间ClassLibraryToDelphi
{
公共静态类测试
{
私有静态的UserControl1 mywindow的;

[DLLEXPORT]
公共静态无效OpenMyWindow()
{
= mywindow的新的UserControl1();
myWindow.ShowDialog();
}
}
}



这里的XAML:

 <窗​​口x:类=ClassLibraryToDelphi.UserControl1
的xmlns =htt​​p://schemas.microsoft.com / WinFX的/ 2006 / XAML /演示
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
的xmlns:MC =HTTP://schemas.openxmlformats .ORG /标记兼容性/ 2006
的xmlns:D =http://schemas.microsoft.com/expression/blend/2008
MC:可忽略=D
D: DesignHeight =300D:DesignWidth =300>
<网格和GT;
<标签内容=WPF窗口德尔福叫! />
< /网格和GT;
< /窗GT;

和代码隐藏:



<预类=郎-cs prettyprint-覆盖> 使用System.Windows;

命名空间ClassLibraryToDelphi
{
公共部分类的UserControl1:窗口
{
公众的UserControl1()
{
的InitializeComponent() ;
}
}
}



我觉得这没有什么特别的或太复杂了重现。



这将是巨大的,如果罗伯特看到了这个问题(其它任何答案都太感激)。



感谢您


解决方案

这是很简单的事了。
在生成-Tab键在你的项目的选项,你必须选择'注册为COM互操作,并在签名必须输入一个强名称。
比你得到一个TLB文件为您的DLL。
在Delphi中你必须去'组件进口和TLB文件添加到您的项目。在DPR-文件,你必须添加Set8087CW($ 133F)bevor在Application.Initialize禁用浮点异常。



这就是它!


I'm using Robert Gieseckes great Unmanaged Exports to call a c#-Dll from Delphi2006. All works well if I use simple procedures and functions with input and output. But now I would like to show a Wpf-Window via the call to OpenMyWindow(). Here I get an "External Exception E0434352". I have no idea why this is not working. Anyway I think it has something to do with Initialization on the wpf side.

Here is the Delphi Code:

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.

and now the c# part (it's a ClassLibrary with an UserControl changed to window):

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();
        }
    }
}

Here's the xaml:

<Window x:Class="ClassLibraryToDelphi.UserControl1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        mc:Ignorable="d" 
        d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Label Content="WPF Window called from Delphi!" />      
    </Grid>
</Window>

and Codebehind:

using System.Windows;

namespace ClassLibraryToDelphi
{
    public partial class UserControl1 : Window
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    }
}

I think it's nothing special or too complicated to reproduce.

It would be great if Robert see this question (any other answer are appreciated too).

Thank you

解决方案

It's quite simple to do that. Under the Build-Tab in your Project-Options you have to select 'Register for COM interop' and under Signing you must enter a strong name. Than you get a tlb-file for your dll. In Delphi you have to go to 'Component import' and add the tlb-file to your Project. In the dpr-file you have to add Set8087CW($133F) bevor Application.Initialize to disable floating point exceptions.

That's it!

这篇关于从调用一个delphi2006 NET的DLL来显示WPF窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆