I need to be able to invoke arbitrary C# functions from C++. http://www.infoq.com/articles/in-process-java-net-integration suggests using ICLRRuntimeHost::ExecuteInDefaultAppDomain() but this only allows me to invoke methods having this format: int method(string arg)
What is the best way to invoke arbitrary C# functions?
When a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.
Just declare the C function extern "C" (in your C++ code) and call it (from your C or C++ code). For example: // C++ code.
Rust can link to/call C functions via its FFI, but not C++ functions.
There are several ways for a C++ application to invoke functions in a C# DLL.
ICLRRuntimeHost::ExecuteInDefaultAppDomain()
) Compile your C++ code with the /clr flag. With that, you can call into any .NET code with relative ease.
For example:
#include <tchar.h> #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { System::DateTime now = System::DateTime::Now; printf("%d:%d:%d\n", now.Hour, now.Minute, now.Second); return 0; }
Does this count as "C++"? Well, it's obviously not Standard C++ ...
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