1

My main application is in C#, and references another .NET DLL that declares IPlugin and IPluginHost. I now need to import this DLL into a Delphi project so I can make a plugin for the main app. I've heard this is possible, but there is so much about importing classes (which I don't want) or running Delphi code within .NET

Has anyone done this before who can clarify?

0

2 Answers 2

3

It will be quite difficult (I am not even sure if it's possible) to implement the .NET interface directly in Delphi. There are, however, a few options available to you depending on how dirty you would like to get your hands.

1) You could create a ActiveX DLL in Delphi and then import this library into .NET. You could then create a proxy class in C# that implements the interface and just route the calls onto the Delphi ActiveX DLL.

2) You could create a native windows DLL in Delphi and then code the interface in .NET. You could then create a proxy class in C# that implements the interface and just route the calls onto the Delphi DLL.

3) You could use a plugin framework like Hydra (http://www.remobjects.com/hydra/) that supports both .NET and Delphi.

In all of these cases you should be careful to handle the 32/64 bit situations as .NET code is capable of running in both but the Delphi code would need to be compiled for each environment independently.

Another option depending on your situation might be to write the Delphi code in a form of object pascal that will produce .NET byte code called Oxygene (http://www.remobjects.com/oxygene/).

Edit: If you are trying to create Delphi plug-ins for use in your .NET plugin framework it would be best to do something like this:

Create a new interfaces in Delphi that match your IPlugIn and IPlugInHost interfaces. You could then build a .NET Delphi plugin wrapper that will have some configuration information to specify which Delphi plugin to load. This .NET wrapper would then load the Delphi DLL and call the DLL methods as required. Visual stuff would need some sort of ActiveX wrapper but you should be able to use the non visual stuff fine.

Sign up to request clarification or add additional context in comments.

8 Comments

What if the interface is declared somewhere else? It's already in a separate file, is there a more appropriate/intercompatible framework I could be using there instead?
You could declare an interface in Delphi and use that on the Delphi side but I am not sure that it will help much. Are you trying to host one Delphi "plug-in" or multiple ones?
About COM / Active X: potential issue is that you shall register the COM object as administrator so your application can't be stand-alone (unless your create the corresponding .reg file by hand and import it not in HKEY_LOCAL_MACHINE but HKEY_CURRENT_USER).
Another link to add, e.g. better than Hydra for working with low-level .Net CLR structures is managed-vcl.com With this library, you can do exactly what the OP needs with no difficulty.
Unfortunately managed-vcl can't (and neither can the Atozed solution): From their site "Managed VCL can not: Query .Net interface if it is not COM visible.". I also can't see how it would be possible to implement a .NET interface in Delphi code which seems to be the crux of his problem. From the looks of the question he is trying to allow the creation of Delphi plug ins for a .NET plug in framework. On the Active X side, that is a restriction, the best bet would be to go with the second option.
|
2

The easiest way is to provide a .NET to COM wrapper dll for delphi. I found out that this is by far the most painless way to interact with .NET.

3 Comments

Could you explain how that will help produce Delphi code that implements .net interfaces.
that's my point you don't implement the interface in delphi, you create a COM compatible .NET gateway/wrapper which implements the .NET interfaces and you expose the needed functionality via COM.
That detail should be in the answer. It's not obvious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.