0

I have made a c++ mfc project and c# class library the mfc project is compiled using Common Language Runtime Support (/clr), and the c# project is included by reference in side the mfc app. The mfc app has a class called Manage which calls c# functions:

managed.h:

class Managed abstract
{
public:
    static void showcswindow(CString name, CString username);
    
};

managed.cpp:

#include "stdafx.h"
#include "Managed.h"

#using <System.dll>
using namespace System;

using namespace ::gettingdatafromc;

void Managed::showcswindow(CString name,CString sername)
{
    services::showwindow(gcnew String(name), gcnew String(sername));
}

c# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace gettingdatafromc
{
    public static class services
    {

        public static void showwindow(string name, string sername)
        {

            string _name = name;
            string _sername = sername;
        }

    }
}

when is use the Managed::showcswindow() in my mfc app it calls directly the c# function I can jump from c++ to c# code.

My question is how to do this but in the opposite way? That is to call c++ from c# and jump to the c++ function location inside the c++ file and execute it.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
med
  • 45
  • 5
  • 5
    Does this answer your question? [How to call from C# simple function in C++ DLL](https://stackoverflow.com/questions/21160662/how-to-call-from-c-sharp-simple-function-in-c-dll) – marsh-wiggle Dec 31 '21 at 09:07
  • 1
    Comment from @marsh-wiggle seems to be working for you but here is an additional information. If your C++ code is compiled with /CLR option then you can refer and use that just like you add reference to C# DLL. – Ashutosh Raghuwanshi Dec 31 '21 at 16:37

0 Answers0