tags:

views:

330

answers:

5

How delphi7 access C# .net managed dll ?

i'm trying to access some DLL that compiled in c# and they are not those old style DLL. ( i dont have source for those DLL)

i did tried to search online but they are confusing. i guess there is some limitation even if get to access it with D7 ..

thanks.

+1  A: 

Delphi7 accesses managed DLLs in the same manner as any other COM-based language (such as VB6).

The basic drill is this:

  1. Make sure your .NET is strong-named.
  2. Run it through regasm
  3. Drop it into the GAC

Now Delphi7 should be able to reference the TLB file that was generated by regasm as it would any other COM-based DLL.

AngryHacker
+5  A: 

@AngryHacker, For what you have suggested to be true, the .NET Assembly needs to be marked with the ComVisibleAttribute ( Register for COM Interop option enabled), and expose each function to COM using the [ComVisible(true)].

If you are trying to use a third party assembly (which you did not write) you have to check with the vendor whether that assembly can be used through COM.

Also the assembly does NOT need to be strong named to be accessible via COM.

If you do not want to go the COM way, check out CrossTalk for Delphi : http://www.atozed.com/CrossTalk/Docs/index.EN.aspx

GX
+1  A: 

You could try to use the "Inverse P/Invoke" trick as described by Brian Long a long time ago.

That trick does not need ComVisible (so you should be able to use it without changing the sources of the .NET assembly).

--jeroen

Jeroen Pluimers
A: 

If you don't have the ability to change the source of the original DLL, you can write a proxy in C# or Prism that exposes a com interface that you can use in your project. The advantage of this approach is you can tailor each call to just use specific types you can handle easily.

skamradt
+1  A: 

That's not hard at all. You do not have to "regasm" it if you don't want to. You don't even have to register anything COM-ish at all.

You'd be best served by creating a wrapper in C# or another managed language. Oh and make sure your classes are ComVisible(true). This Stack Overflow thread sums it up quite nicely, and itcomes with a set of examples for different scenarios. http://stackoverflow.com/questions/2048540/hosting-clr-in-delphi-with-jcl-example/2055508#2055508

Robert Giesecke