Building a Managed .NET Framework Application (3)

December 5, 2009

Now that you’ve added the member variables, its time to add some member functions. Right-click the CHelloNETForm class again, but this time select Add, Add Function. Enter void as the return type, InitForm as the function name, and an access level of protected. Click Finish to close the dialog.

The last step to finish the design of the class is to add the necessary elements that are not supported by wizards within the IDE. Using Listing 3.1 as a guide, add the appropriate using statements and add the __gc keyword immediately preceding the class keyword. This indicates to the compiler that the class is managed by the .NET Framework and its memory manager.

When you are finished, you’re HelloNETForm.h file should look similar to Listing 3.1.

Listing 3.1 Transforming a Generic C++ class into Managed Code
1: #pragma once
2:
3: #using
4:
5: #using
6: #using
7: #using
8:
9: using namespace System;
10: using namespace System::Windows::Forms;
11:
12: __gc class CHelloNETForm : public Form
13: {
14: public:
15: CHelloNETForm(void);
16: ~CHelloNETForm(void);
17: protected:
18: Button* m_pbtnMessage;
19: Button* m_pbtnDone;
20: Label* m_pstMessage;
21: System::ComponentModel::Container* m_pComponents;
22: void InitForm();
23: };

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

Leave a Reply