调用C#从德尔福DLL [英] Call C# dll from Delphi

查看:228
本文介绍了调用C#从德尔福DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我组成的.Net 3.5 DLL使用单一的方法,这是德尔福.exe文件来调用。 遗憾的是它不工作。

的步骤: 1.创建C#3.5的dll与code:

 公共类MyDllClass
{
    公共静态INT MyDllMethod(int i)以
    {
        的MessageBox.show(数为+ i.ToString());
    }
}
 

  1. 转到大会属性 - >程序集信息,并检查了使大会COM可见
  2. 二手RegAsm.exe注册我的DLL

这将引发德尔福例外,这表明它无法连接的DLL。 什么是需要从非托管code C#托管DLL启用的使用步骤。

是否熟悉这个话题很好的例子吗?

任何一个

感谢您

解决方案

在大规模的调查中,我找到了解决方法:这是所有关于注册参数。 标志/ codeBase的必须被添加到该regasm命令。

很多帖子在那里建议使用GUID和关于C#的COM暴露对象的其他COM属性,我设法用标记有ComVisible特性(真)属性来提供COM功能和regasm / TLB / codeBSE命令。

在code:

  [的Guid(7DEE7A79-C1C6-41E0-9989-582D97E0D9F2)]
[标记有ComVisible特性(真)
公共类ServicesTester
{
    公共ServicesTester()
    {
    }

    // [标记有​​ComVisible特性(真)
    公共无效TestMethod的()
    {
        的MessageBox.show(你在TestMethod的功能);
    }
}
 

和我提到我用regasm.exe / TLB / codeBase类进行注册。

I composed .Net 3.5 dll with single method, which is to be called by Delphi .exe. Unfortunately it does not work.

The steps: 1. Create C# 3.5 dll with the code:

public class MyDllClass
{
    public static int MyDllMethod(int i)
    {
        MessageBox.Show("The number is " + i.ToString());
    }
}

  1. Go to Assembly Properties --> Assembly Information and checked the "Make Assembly COM-Visible"
  2. Used RegAsm.exe to register my dll

This throws Delphi exception which indicates it cannot connect the dll. What are the steps required to enabled usage of C# managed dll from unmanaged code.

Does any one familiar with good example about the subject?

Thank you

解决方案

After massive investigation I found the solution: it's all about registration parameters. The flag /codebase must be added to the regasm command.

Many posts out there suggest to use Guid and other COM attributes on the C# Com exposed object, I managed to deliver COM functionality using the ComVisible(true) attribute and regasm /tlb /codebse command.

The code:

[Guid("7DEE7A79-C1C6-41E0-9989-582D97E0D9F2")]
[ComVisible(true)]
public class ServicesTester
{
    public ServicesTester()
    {
    }

    //[ComVisible(true)]
    public void TestMethod()
    {
        MessageBox.Show("You are in TestMEthod Function");
    }
}

and as I mentioned I used regasm.exe /tlb /codebase to register it

这篇关于调用C#从德尔福DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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