How do I call methods in C # dll from my C code?

I am trying to create integration between a third-party Lisp program (let it be called ABC) and a C # program that I wrote myself (let it be called DEF). The problem is that ABC can only reference assemblies created in C or Fortran. So, I started learning C, and I got the test "hello world", where ABC calls my C dll and gets a "hello world" in return. I tried calling dll dll from C code using explicit loading and GetProcAddress. This worked if I called another C dll, but not C # dll. Now I'm wondering if I should learn C ++ and call C # from C ++ to create this nice chain of calls:

ABC → C → C ++ → DEF (C #) → C ++ → C → ABC

If this is the only way, can someone help me with some examples, etc.?

+6
source share
2 answers

Use this project to export C # functions as entry points.

+2
source

When you create a .NET assembly, you can check the box so that the assembly is registered for COM interoperability. This will allow you to access it from any language that COM can call. (C can it?? For a long time since I touched C or C ++.)

Configuration Properties → Create Project Properties Page. Find "Register for COM Interoperability."

+3
source

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


All Articles