开发者

How to communicate between a c# and a Delphi application?

开发者 https://www.devze.com 2023-02-24 10:46 出处:网络
I need to interface my application (Delphi+MS SQL Server: D from now on) with another application (c#+SQL Server: C from now on).

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开发者_如何学C single exe (win32).

Which technique do you suggest?


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.


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.


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 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.


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.


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.


You can use ZeroMQ. It is a free message oriented stack.


My framework can run under both Delphi and Visual Studio and thus allows communication between Win32 and .NET applications across raw TCP sockets.


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#.

0

精彩评论

暂无评论...
验证码 换一张
取 消