none
VC2008: Error depending on CLR settings when using derived form classes RRS feed

  • Question

  • Hi,

    I have an error I don't understand. Here's what I did.

    I created a new Windows Forms test application in C++/CLI.

    After that I added a new class derived from System::Windows::Forms::Form to the project and changed the base class in Form1.h from System::Windows::Forms::Form to my new base class "form2" ...

    public ref class form2 : public System::Windows::Forms::Form {
    
    public: form2() : System::Windows::Forms::Form() {
    
    }

    ... I can compile and run the application without problems using /safe, /pur or /clr. But when I want to open Form1.h in the designer again I get an error when /clr was used for compiling. But I need to compile my other application using /clr because of using some other native C++ stuff and some function from WinMM.lib.

    Is there a reason why the Forms Designer has problems with derived classes in /clr? When I derive Form1 from the original System::Windows::Forms::Form class everything is fine even when using /clr.

    Wednesday, March 16, 2011 6:27 AM

Answers

  • Hi wannabe_2,

    I have test this feature in my environment, both in design mode and runtime are all work fine.

    I just create a new CPP windows form project, and then add a form named Form2. Then change the Form2's base class to Form1.

    It works fine when I open the Form2 in vs designer.

    You can download this test project, and test it in your side, and let us know the result.

    http://cid-bb789f72272d4858.photos.live.com/self.aspx/2011/2011Y03M/CPPWinForm032101.zip (Download this vs2008 CPP project)

    You also can download this one:

    http://cid-bb789f72272d4858.photos.live.com/self.aspx/2011/2011Y03M/CPPWinForm032301.zip

     

    please note:

     

    But As far as I know, if we want use the vs designer works at design time, we need compile the assembly with the /clr:pure option to let the assembly compiled to a pure MSIL application, then the vs designer can reflector over the resulting assembly file and load the control for using the windows Form designer.

    This information has mentioned in the MSDN document, you can reference it:

    Walkthrough: Using /clr:pure Features 

    When compiled into a pure MSIL application, the Visual Studio Windows Forms designer is able to reflect over the resulting EXE file and load the managed control for use in the Windows Forms designer. This behavior is possible only when the current configuration is to create a pure MSIL application, and not in an unmanaged or mixed mode.

     

    If there's any concern, please feel free to let us know.

    Have a nice day!


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.




    Friday, March 18, 2011 9:34 AM
    Moderator

All replies

  • Hi wannabe_2,

    I have test this feature in my environment, both in design mode and runtime are all work fine.

    I just create a new CPP windows form project, and then add a form named Form2. Then change the Form2's base class to Form1.

    It works fine when I open the Form2 in vs designer.

    You can download this test project, and test it in your side, and let us know the result.

    http://cid-bb789f72272d4858.photos.live.com/self.aspx/2011/2011Y03M/CPPWinForm032101.zip (Download this vs2008 CPP project)

    You also can download this one:

    http://cid-bb789f72272d4858.photos.live.com/self.aspx/2011/2011Y03M/CPPWinForm032301.zip

     

    please note:

     

    But As far as I know, if we want use the vs designer works at design time, we need compile the assembly with the /clr:pure option to let the assembly compiled to a pure MSIL application, then the vs designer can reflector over the resulting assembly file and load the control for using the windows Form designer.

    This information has mentioned in the MSDN document, you can reference it:

    Walkthrough: Using /clr:pure Features 

    When compiled into a pure MSIL application, the Visual Studio Windows Forms designer is able to reflect over the resulting EXE file and load the managed control for use in the Windows Forms designer. This behavior is possible only when the current configuration is to create a pure MSIL application, and not in an unmanaged or mixed mode.

     

    If there's any concern, please feel free to let us know.

    Have a nice day!


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.




    Friday, March 18, 2011 9:34 AM
    Moderator
  • Sorry Mike,

    you project is a VS2010 project. I'm using VS2008. I cannot open it. I created a new Forms project and copied you file (cpp, h and resouces) to the new folder. But the same error.

    Does that mean that in VS2010 this works. I search the internet and a lot of people say (2005/2008) cannot handle derived classes in forms.

    Unfortunately the upgrade from 2008 Standard Edition to 2010 Professional is sold out at the moment as it seem.

    Sunday, March 20, 2011 7:18 AM
  • Hi wannabe_2,

    Sorry for the mistake.

    I have wrote a vs2008 CPP project, and update the link in my last post.

     

    If there's any concern, please feel free to let us know.

    Have a nice weekend!


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 21, 2011 6:36 AM
    Moderator