Managed Code Access (CLR) DLL with Delphi 7

How does delphi7 access a c # .net managed dll?

I am trying to access some DLL compiled in C # and they are not that old style DLL. (I have no source for these DLLs)

I tried to search the Internet, but they are confusing. I assume there are some limitations, even if you access it using D7 ..

thanks.

+4
source share
5 answers

@AngryHacker. For what you assumed to be true, the .NET assembly must be marked with the ComVisibleAttribute parameter (Register for COM Interop parameter is enabled) and exposes each COM function using [ComVisible (true)].

If you are trying to use a third-party assembly (which you did not write), you need to check with the supplier if this assembly can be used through COM.

Also, the assembly must NOT be a strong named for access through COM.

If you don’t want to go in COM mode, check out CrossTalk for Delphi: http://www.atozed.com/CrossTalk/Docs/index.EN.aspx

+5
source

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

The main exercise:

  • Make sure your .NET is a strong name.
  • Run it through regasm
  • Leave it to the gac

Delphi7 should now be able to reference the TLB file that was generated with regasm , just like any other COM-based DLL.

+1
source

You can try using the “Reverse P / Invoke” trick as described by Brian Long a long time ago.

This trick is not needed by ComVisible (so you can use it without changing the sources of the .NET assembly).

- Jeroen

+1
source

This is not difficult. You do not need "regasm" if you do not want it. You do not even need to register any COM-ish at all.

You will be best off working by creating a wrapper in C # or another managed language. Oh, and make sure your classes are ComVisible (true). This thread summarizes it pretty well, and it meets with a set of examples for different scenarios. CLR Hosting in Delphi with / without JCL - Example

+1
source

If you are unable to change the source of the source DLL, you can write a proxy server in C # or Prism, which provides a com interface that you can use in your project. The advantage of this approach is that you can adapt each call to the simple use of certain types that you can easily handle.

0
source

Source: https://habr.com/ru/post/1305890/


All Articles