Search code examples
winformsvisual-studioinstallationidec++-cli

Identifier form is undefined


How can I solve the problem:

enter image description here

I am very new to C/C++ so I do not know what info I have to give in order to describe my problem properly. All that I was doing is trying to incorporate Windows Forms following step by step after the guy here. He got everything working and I do not even though I did exactly the same stuff as he did.

Here is the code with the error:

using namespace System;
using namespace System::Windows::Forms;

[STAThreadAttribute]
void Main(array<String^>^ args) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Project1::MyForm form;
    Application::Run(%form);
}

Solution

  • You should really save yourself a lot of pain and use C# for your GUI and only use C++/CLI to wrap native unmanaged C++ code within your C# GUI.

    Anyway, Project1 is not a namespace so just drop it. Try this:

    using namespace System;
    using namespace System::Windows::Forms;
    
    [STAThreadAttribute]
    void Main(array<String^>^ args) {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        MyForm form;
        Application::Run(%form);
    }