Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call C# dll from unmanaged C++ app without COM

Is there a way to call c# dll from c++ unmanaged application without COM usage?

like image 920
Victor Ronin Avatar asked Dec 16 '10 21:12

Victor Ronin


People also ask

What is call in C?

The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. It means the changes made to the parameter affect the passed argument.

Is call by value in C?

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. By default, C programming uses call by value to pass arguments.

What is call by reference in C with example?

In call by reference, we pass the address of a variable. So, if we modify the value, it will affect the original value of a variable. #include<stdio.h> void print(int *a) { printf("From print function ...\ n"); printf("Address of a = %p\n",a); } int main() { int a = 10; printf("From Main Function ...\


2 Answers

You can do this using Reverse P/Invoke - example and discussion here.

like image 135
Steve Townsend Avatar answered Sep 21 '22 13:09

Steve Townsend


It is actually possible to disassemble, modify the IL, and reassemble it with exported functions. I messed with this a few years ago, and created an application that would disassemble a dll, provide a list of functions that could potentially be exported - allowing the user to select them, then re-write the IL and reassemble everything. Then, I could call directly into the dll from unmanaged code...or p-invoke into the dll from managed code (not really practical, but interesting nonetheless).

Surely there is a reason that this isn't supported in the .net languages themselves (even tho it is supported in MSIL). I wouldn't use this in production:

Dead link: http://www.csharphelp.com/2007/03/exporting-managed-code-as-unmanaged/

Wayback Machine: https://web.archive.org/web/20140213030149/http://www.csharphelp.com/2007/03/exporting-managed-code-as-unmanaged/

like image 41
Eric Dahlvang Avatar answered Sep 22 '22 13:09

Eric Dahlvang