Calling C# code from C++, but ExecuteInDefaultAppDomain() is too limited
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++ ...
C# Code in C++ Project
It means, that with the /clr
switch, you can access assemblies (DLL or EXE) written for the .Net framework. Because such assemblies can be created with any .net language (including C#), you can use "code" written in C# from within C++, but it doesn't mean that you would be able to write C# in C++ project. Unfortunately - you can't.
Call C# dll from unmanaged C++ app without COM
You can do this using Reverse P/Invoke
- example and discussion here.
Questions about Calling C# function from C++, Reversed P/Invoke on windows phone
OK, I just realize some part of me is wrong,
I just know what is Reverse P/Invoke:
Reverse P/Invoke means:
Start the project in C#,
Create a C# delegate function.
Create a C++ dll.
Call a function in C# -> call a function in C++ -> call the C# delegation function.
This is how the function stack look like:
|-> C# delegate function
|-> C++ dll function
|-> C# main function
Is that correct?
So this is not calling a C# function from C++ ....
What do I do if I want to call a C# function from C++ ....
I mean, I want to start a C++ project, and call a C# function in that C++ project....
Related Topics
Checking for Null Before Event Dispatching... Thread Safe
Round a Double to X Significant Figures
How to Create/Edit a Manifest File
Change Attribute's Parameter at Runtime
How to Enumerate All Windows Belonging to a Particular Process Using .Net
Dependency Injection Unity - Conditional Resolving
Best /Fastest Way to Read an Excel Sheet into a Datatable
How to Enable Http Put and Delete for ASP.NET MVC in Iis
Differencebetween Await Task<T> and Task<T>.Result
How to Count Duplicates in List with Linq
Calling C# Code from C++, But Executeindefaultappdomain() Is Too Limited
What Is the C# Version of Vb.Net's Inputdialog
Reading Datetime Value from Excel Sheet
String.Split - by Multiple Character Delimiter
Why Implement Interface Explicitly