access managed code ( CLR ) DLL with Delphi 7
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 开发者_如何学Cto search online but they are confusing. i guess there is some limitation even if get to access it with D7 ..
thanks.
@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
Delphi7 accesses managed DLLs in the same manner as any other COM-based language (such as VB6).
The basic drill is this:
- Make sure your .NET is strong-named.
- Run it through regasm
- 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.
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
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. Hosting CLR in Delphi with/without JCL - example
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.
精彩评论