English 中文(简体)
我如何利用C#应用中的Delphi代码?
原标题:How can I use Delphi code from a C# application?
  • 时间:2011-05-18 09:21:59
  •  标签:
  • c#
  • delphi

我有一个德尔菲项目,我需要撰写一份C#申请,但我想利用这个德尔菲项目的一些职能。 我先在德尔菲工作。

我发现,我可以从《德尔菲法》中设立一个DL,并在C#中直接使用。 我如何能够这样做? 或者,我还发现一些转换工具,以转换为C#,但这种工具却不错。 因此,最佳方式是什么? DL或转化?

问题回答

Here is a very quick sample explains how to make dll in Delphi and then how to call it from C#. Here is Delphi code of simple dll with one function SayHello:

library DllDemo;

uses
  Dialogs;

{$R *.res}

Procedure SayHello;StdCall;
Begin
  ShowMessage( Hello from Delphi );
End;

exports
  SayHello;

begin
end.

编篡这一法典,并编造一个文件。

现在,用“C#”法来说明先前的批次程序:

using System.Runtime.InteropServices;

namespace CallDelphiDll
{
  class Program
  {
    static void Main(string[] args)
    {
      SayHello();
    }

    [DllImport("DllDemo")]
    static extern void SayHello();
  }
}

Put,Delphi在C#项目产出目录中产生批量,并管理C#应用。

现在,扩大这一简单样本,以达到你的要求。

正如已通过《刑法》建议的那样(青年需要用诸如轮值之类的适当的电话公约来标明职能)

一种不同的解决办法是,在COM标中总结相关功能,并使用这一功能。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签