How do I program C++ and C# simultaneously in Visual Studio?

Caua Cabral 20 Reputation points
2023-10-08T23:32:41.9266667+00:00

I asked almost everywhere and didn't get an answer, I ended up realizing that it is possible to use C++ and C# In Visual Studio simultaneously, but I don't know how I can do this, and I would also like to know if it is possible to apply this in Windows Forms, if so, how do I do it? Is there any tutorial? Forum? I'm really lost on this. Any help I would appreciate

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,389 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,562 questions
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 10,436 Reputation points Microsoft Vendor
    2023-10-09T02:18:11.8366667+00:00

    Hi, @Caua Cabral

    Do you need C++CLR?

    You could install C++CLI support in Visual Studio Installer.

    User's image

    Create a CLR empty project (.Net Framework) and add new item -> CLR Winform.

    Add code in .cpp to run form:

    #include "MyForm.h"
    
    using namespace System;
    using namespace System::Windows::Forms;
    
    [STAThread]
    int main(array < String^>^ args)
    {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(0);
        //Project1 Namespace  in MyForm.h
        Project1::MyForm form;
        Application::Run(% form);
    }
    

    Here is the document: .NET programming with C++/CLI

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,201 Reputation points
    2023-10-09T00:01:19.3066667+00:00

    Each language will have its own project and can be used by each other when each project targets the same .NET Framework or .NET Core Framework.

    0 comments No comments