如何在 ac# 和 Delphi 应用程序之间进行通信?
我需要将我的应用程序(Delphi+MS SQL Server:从现在开始为 D)与另一个应用程序(从现在开始为 c#+SQL Server:C)连接。
C 有一个简约的 Windows 窗体用户界面,它的主要工作是连接到 PDA,发送和接收来自 PDA 的数据。
所以他们的想法是删除 C 用户界面的 UI,只保留与 DB 和 PDA 通信所需的代码。
所以我需要 C 可以与 D 通话,反之亦然。
D 到 C:因此,在某些事件上(例如 TButton.OnPress),D 会向 C 发送一些数据。所以我需要调用 C 公开的方法。
C 到 D:D 需要对 C 执行的某些操作做出反应。所以 C将调用 D 公开的一些方法。即使在第一阶段,D 也只是“公开存储过程”。
我从来没有做过这样的事情。该怎么办? D 目前是单个 exe (win32)。
您建议采用哪种技术?
I need to interface my application (Delphi+MS SQL Server: D from now on) with another application (c#+SQL Server: C from now on).
C has a minimalistic Windows Forms user interface and the big job it does is connecting to PDAs sending and receiving data from them.
So they idea is that the UI for the C user interface is removed and they just keep the code needed for communication with DB and with PDA.
So I need that C can speak to D and vice versa.
D to C: So somehow on some events (like TButton.OnPress) D will send some data to C. So I need to call methods exposed by C.
C to D: D needs to react to some actions performed by C. So C will call some methods exposed by D. Even if in the first stage D will just "expose a stored procedure".
I never did something like this. What to do? D is currently a single exe (win32).
Which technique do you suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果要删除 C 中的用户界面,那么我建议将 C 包装在单个 COM 对象中,您可以从 Delphi 中透明地使用该对象。
If the user interface in C is going to be removed, then I would recommend to wrap C in a single COM object that you can use transparently from Delphi.
有很多选择。套接字可能是最强大的,但如果两个应用程序在同一台计算机上运行,您可以使用窗口消息(
WndProc
和朋友)或命名管道。There are a plethora of options. Sockets are probably the most robust, but if both apps run on the same machine you can use window messages (
WndProc
and friends) or named pipes.我认为你可以使用套接字。要么使用自己的协议,要么使用网络服务,但后者相当复杂。 Delphi 有 WSDL 导入程序,C++ 有 gSOAP 库。
I think you can use sockets. Either with your own protocol or you can go for webservices, but the latter is quite complicated. Delphi has WSDL importer a C++ has gSOAP library.
RemObjects SDK 本身支持 Delphi 和 .NET 程序。它是较低级别之上的附加层,但可能会让事情变得更容易。
RemObjects SDK supports both Delphi and .NET programs natively. It's an additional layer over something lower level, but might make things easier.
如果它们都使用相同的数据库,您可以将其用作它们之间的管道。
在一个应用程序中写入特定的表,而在另一个应用程序中,通过定期轮询该表来“监听”该表,删除任何已处理的“消息”。
这是一般的想法,好处是您现在就可以做到这一点,而无需使用任何库。
If they both use the same database, you can use it as the pipe between them.
In one application write into specific table and in the other "listen" to that table by polling it on regular intervals, deleting any "message" already handled.
That's the general idea, upside is that you can do it right now without using any libraries.
我正在做一个类似的应用程序,我使用现有的 Delphi 应用程序与我的新 .NET 应用程序进行通信。我将应用程序包装到 DLL 中,并使用公开的函数从 .NET 进行调用,并使用回调过程从 .NET 与 Delphi 进行通信。
I am doing a similar kind of application where I am using my existing Delphi application to communicate to my new .NET app. I wrapped the application into a DLL and used the exposed functions to call from .NET as well as a Callback proc to communicate form .NET to Delphi.
作为选项之一,我可以提供 MsgConnect,这是一个轻量级的面向消息的中间件,可以解决轻松解决你的问题。 MsgConnect 可用于 Delphi 和 C#。上面提到的 RemObjects SDK 也是一个很棒的产品,尽管对于您的简单任务来说可能有点大材小用。
As one of the options I can offer our MsgConnect, which is a lightweight message-oriented middleware that would solve your problem easily. MsgConnect is available for both Delphi and C#. RemObjects SDK, mentioned above, is also a great product, though probably a bit overkill for your simple task.
您可以使用 ZeroMQ。它是一个免费的面向消息的堆栈。
You can use ZeroMQ. It is a free message oriented stack.
我的框架可以在 Delphi 和 Visual Studio 下运行,因此允许 Win32 和 .NET 应用程序之间通过原始 TCP 套接字进行通信。
My framework can run under both Delphi and Visual Studio and thus allows communication between Win32 and .NET applications across raw TCP sockets.
您可以将 C# 代码转换为 DLL(类库)。设置选项“使程序集 COM 可见”。创建新证书(如果需要)并签署您的代码。
在 Windows 中注册您的 C# DLL:“RegAsm -tlb -codebase YourLibrary.dll”。
在 Delphi 中导入您的库(组件 -> 导入组件,选择“类型库”,选择您的库,“创建单元”)。
在 Delphi 中,使用 C# 库的方式与使用 COM 对象(例如 OLE 自动化或 ActiveX)的方式相同。
您可以创建用于 Delphi 和 C# 之间通信的接口。如果您这样做,那么您可以轻松实现 Delphi 代码和 C# 代码之间的双向通信。
You can convert your C# code to a DLL (Class Library). Set option "Make assembly COM-Visible". Create new certyficate (if required) and sign your code.
Register your C# DLL in Windows: "RegAsm -tlb -codebase YourLibrary.dll".
In Delphi import your library (Component -> Import Component, select "Type library", select your library, "Create Unit").
In Delphi use your C# library the same way like you are using COM objects (e.g. OLE Automation or ActiveX).
You can create interface(s) for communication between Delphi and C#. If you do this then you can easy implement two-way communication between you code in Delphi and your code in C#.