Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

c#

I am trying to create an integration between a 3rd party Lisp-based program (Let's call it ABC) and a C# program I have written myself (let's call it DEF). The problem is that ABC can only call assemblies created in C or Fortran. So I started learning C, and I got the "hello world" test to work, where ABC call my C dll and gets "hello world" in return. The I tried to call my DEF dll from the C code using explicit loading and GetProcAddress. It worked if I called another C dll, but not a C# dll. Now I wonder if I must learn C++ and call C# from C++ to create this nice call chain:

ABC -> C -> C++ -> DEF(C#) -> C++ -> C -> ABC

If that is the only way, can anyone help me with some examples etc?

like image 999
AndersJH Avatar asked Apr 26 '12 14:04

AndersJH


1 Answers

When you create a .NET assembly, you can set a checkbox to have the assembly registered for COM interop. This will allow you to access it from any language that can call COM. (C can can't it? Been a long time since I touched C or C++.)

Configuration Properties -> Build page of your project properties. Look for "Register for COM Interop".

like image 123
sschrass Avatar answered Sep 20 '22 14:09

sschrass