从C调用C#code ++ [英] Calling C# code from C++
问题描述
我需要能够从C调用任意C#函数++。 <一href=\"http://www.infoq.com/articles/in-process-java-net-integration\">http://www.infoq.com/articles/in-process-java-net-integration建议使用ICLRRuntimeHost :: ExecuteInDefaultAppDomain(),但这个只允许我引用有这个格式的方法: INT方法(String ARG)
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)
什么是调用任意C#功能的最佳方式?
What is the best way to invoke arbitrary C# functions?
推荐答案
与 / CLR 标志编译C ++ code。有了这一点,你可以拨打到任何.NET code相对容易。
Compile your C++ code with the /clr flag. With that, you can call into any .NET code with relative ease.
例如:
#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;
}
请问这算不算C ++?嗯,这显然不是的标准C ++ ...
这篇关于从C调用C#code ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!