Is there a way to call c# dll from c++ unmanaged application without COM usage?
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.
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.
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 ...\
You can do this using Reverse P/Invoke
- example and discussion here.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With