none
Applying C++ to CLR in Visual Studio 2012 Pro RRS feed

  • Question

  • This is my first time dealing with a full project/using something other than the console window, so if anyone could help me it would be much appreciated. Also if I'm on the wrong forum category I apologise; first time on the windows forum ;)

    I created a new C++/CLR/Empty Project, added Windows to Configuration Properties>Linker>System>SubSystem and added "Main" to the Advanced>Entry Point.

    The header files that opened as default I have left, and lastly my BMI.cpp file has the header file included.

    On my main page .cpp I have:

    #include "MAINPAGE.h"

    #include "BMI.h"

    using namespace System;

    using namespace System::Windows::Forms;

    void Main(){

    Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false);

    MYPORTFOLIO::MAINPAGE MAINPAGEObject;

    Application::Run(%MAINPAGEObject); }

    This is where my error is:

    this->Load += gcnew System::EventHandler(this, &BMI::BMI_Load);

    ================================================

    And the error message:

    http://pastebin.com/7Sb0UM4V


    • Edited by 77Legg Saturday, March 22, 2014 3:49 PM
    • Moved by Amanda Zhu Monday, March 24, 2014 7:11 AM
    Saturday, March 22, 2014 3:46 PM

Answers

  • Hello 77legg,

    From the following code you are able to know how to finish this job and since I have no idea how you defined BMI and BMI_load, I have no idea what's happening in your code.

    using namespace System;
    
    delegate void Del(int, float);
    
    // interface that has an event and a function to invoke the event
    interface struct I {
    public:
       event Del ^ E;
       void fire(int, float);   
    };
    
    // class that implements the interface event and function
    ref class EventSource: public I {
    public:
       virtual event Del^ E;
       virtual void fire(int i, float f) {
          E(i, f);
       }
    };
    
    // class that defines the event handler
    ref class EventReceiver {
    public:
       void Handler(int i , float f) {
          Console::WriteLine("EventReceiver::Handler");
       }
    };
    
    int main () {
       I^ es = gcnew EventSource();
       EventReceiver^ er = gcnew EventReceiver();
    
       // hook the handler to the event
       es->E += gcnew Del(er, &EventReceiver::Handler);
    
       // call the event
       es -> fire(1, 3.14);
    
       // unhook the handler from the event
       es->E -= gcnew Del(er, &EventReceiver::Handler);
    }

    Linked from here: http://msdn.microsoft.com/en-us/library/58cwt3zh.aspx

    Please paste your code about BMI and BMI_load so that we may know some more details.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, March 24, 2014 7:09 AM
    Moderator
  • Hi 77Legg,

    You will just need to know Delegate in C# http://msdn.microsoft.com/en-us/library/ms173171.aspx and event http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx

    ASP.NET is for Web development and you don't need to learn it.

    And for that BMI_load, if you haven't create it, at least you have to do something like:

    ref class BMI{
    public:
       void BMI_load() {
          Console::WriteLine("BMI_loaded");
       }
    };
    

    So that you application can run. It is a little like message handler in C++.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 25, 2014 9:39 AM
    Moderator

All replies

  • !!!!
    Sunday, March 23, 2014 2:52 PM
  • Hello 77legg,

    From the following code you are able to know how to finish this job and since I have no idea how you defined BMI and BMI_load, I have no idea what's happening in your code.

    using namespace System;
    
    delegate void Del(int, float);
    
    // interface that has an event and a function to invoke the event
    interface struct I {
    public:
       event Del ^ E;
       void fire(int, float);   
    };
    
    // class that implements the interface event and function
    ref class EventSource: public I {
    public:
       virtual event Del^ E;
       virtual void fire(int i, float f) {
          E(i, f);
       }
    };
    
    // class that defines the event handler
    ref class EventReceiver {
    public:
       void Handler(int i , float f) {
          Console::WriteLine("EventReceiver::Handler");
       }
    };
    
    int main () {
       I^ es = gcnew EventSource();
       EventReceiver^ er = gcnew EventReceiver();
    
       // hook the handler to the event
       es->E += gcnew Del(er, &EventReceiver::Handler);
    
       // call the event
       es -> fire(1, 3.14);
    
       // unhook the handler from the event
       es->E -= gcnew Del(er, &EventReceiver::Handler);
    }

    Linked from here: http://msdn.microsoft.com/en-us/library/58cwt3zh.aspx

    Please paste your code about BMI and BMI_load so that we may know some more details.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, March 24, 2014 7:09 AM
    Moderator
  • Hi,

    I have moved this thread to Windows Forms General forum for better support.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 24, 2014 7:12 AM
  • I never created a BMI_load, all the info in the .cpp's and .h's came with the new button + main form + BMI class I created.

    I only know how to program in C++ but I want to use Windows Forms...

    But I'm guessing I need to learn CSharp, ASP .NET or something to be able to use forms am I right?

    Monday, March 24, 2014 6:06 PM
  • Hi 77Legg,

    You will just need to know Delegate in C# http://msdn.microsoft.com/en-us/library/ms173171.aspx and event http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx

    ASP.NET is for Web development and you don't need to learn it.

    And for that BMI_load, if you haven't create it, at least you have to do something like:

    ref class BMI{
    public:
       void BMI_load() {
          Console::WriteLine("BMI_loaded");
       }
    };
    

    So that you application can run. It is a little like message handler in C++.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 25, 2014 9:39 AM
    Moderator