views:

1942

answers:

6

Is it possible to use a .NET DLL in Delphi 2007 for Win32? I've tried to import the DLL in the same way I've done for an ActiveX component, but it doesn't appear to work (Component Menu -> Import Component -> Import .NET Assembly.

Is it possible and if so what are the steps?

A: 

I don't think you can do that, directly mixing managed and unmanaged code in the the same app.

However RemObjects have a framework called Hydra that allows you to use .Net and Win32 in the same application.

Simon Temlett
You can even without Hydra
Lars Truijens
If there's a framework for it, then obviously you CAN mix managed and unmanaged code in the same app. This ain't magic.
Rob Kennedy
+1  A: 

Sure you can. You just have to tell it what parts of your code should be accessible that way. You can do that through the ComVisibleAttribute. The quickest fix is putting [assembly:ComVisible(True)] in your .dpk which makes everything public visible. Then you can use the method you tried to import the assembly.

You can also do unmanaged exports which can be called like regular dll files.

Lars Truijens
+3  A: 

Have a look at this MSDN article - it may help you.

Exposing .NET Framework Components to COM

Roddy
A: 

Wrapping the .Net assembly in a COM object is probably your best option.

If the assembly was written in Delphi for .Net, here is an example of using unmanaged exports to use it just like any other .dll.

http://cc.codegear.com/Item/22688

The downside is that this is not (yet) supported by Prism.

Bruce McGee
+4  A: 

If you want a Delphi specific article on doing that:

Using a .NET Assembly via COM by Jim McKeeth

It is pretty straight forward once you have all the steps.

Jim McKeeth
+1  A: 

CrossTalk from Atozed Software allows to use .NET assemblies from Delphi without using COM, no DLL registration and can use original assemblies without modification.

http://atozed.com/CrossTalk