Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf
NAMESPACES AND ATTRIBUTES Appendix C 961
commonly available dialog boxes. For example, the OpenFileDialog class provides the functionality of the Open dialog box.
To summarize, the System namespace comprises the main namespace in the
.NET Framework that simplifies the creation of applications by using Visual Studio.NET.
Attributes
As specified in Chapter 18, there are five predefined categories of attributes available for you to work with:
COM attributes
IDL attributes
ATL Server attributes
OLEDB consumer attributes
Compiler attributes.
The following sections describe some of the attributes belonging to each of these categories.
COM Attributes
As you have experienced by now, COM attributes reduce your coding effort to a great extent. Some of the COM attributes are the following:
coclass. Creates a COM component.
aggregatable. Specifies that a component can be aggregated by others.
aggregates. Specifies that the component aggregates the target class.
progid. Defines the ProgID for a component.
com_inteface_entry. Creates an entry in the COM map for an interface.
perf_counter. Adds performance counter support to a specific class member.
soap_handler. Provides methods for processing SOAP messages.
synchronize. Synchronizes simultaneous access to a component’s method.
threading. Specifies the threading model for a component.
962 |
|
Part XII |
APPENDIXES |
|
|||
|
|
|
|
IDL Attributes
To maintain an IDL file, earlier you had to have the knowledge about the structure of the IDL file and had to rely on the wizard that allowed you to selectively modify the file. Now with IDL attributes, you have the facility to modify the IDL file from within its source code. IDL attributes can be used either in combination with the COM attributes or as standalone attributes. With COM, the IDL attributes inject code into the project. While used alone, these allow you to define interfaces and the IDL file. Some of the IDL attributes are listed here:
id. Specifies a DISPID for a function.
dispinterface. Places an interface as a dispatch interface in the IDL file.
dual. Places an interface as a dual interface in the IDL file.
include. Specifies the header files to be included in the IDL file.
import. Specifies the IDL or H files that you want to refer to from the main IDL file.
in. Specifies that the parameter is to be passed to the called procedure.
coclass. Places a class as a coclass in the IDL file.
out. Identifies the parameters received from the server.
progid. Specifies the ProgID of an object.
ATL Server Attributes
The ATL Server template provides an option to use the ATL Server attributes while creating an ATL Server. Some of the attributes under this category are the following:
soap_handler. Provides the methods required to handle SOAP-related messages.
soap_method. Exposes the specified method as a SOAP method and generates the WSDL description.
soap_header. Assigns a member to hold the header information in a SOAP message.
request_handler. Exposes a class as an ATL Server request handler.
NAMESPACES AND ATTRIBUTES Appendix C 963
OLE DB Consumer Attributes
The OLEDB attributes inject code to create an OLEDB consumer with the functionality of the commonly performed operations that include opening a table, executing commands, and retrieving data. Some of the attributes under this category are the following:
db_table. Opens a table.
db_source. Creates a connection.
db_param. Associates a variable with an input or output parameter.
db_command. Executes an OLEDB command.
db_column. Binds a column to a rowset.
Compiler Attributes
Some of the compiler attributes are the following:
event_receiver. Creates an event receiver.
event_source. Creates an event source.
version. Identifies a particular version of a class or an interface.
This page intentionally left blank
Managed code enables you to utilize the significant features of the .NET Framework, such as the CLR, garbage collection, and JIT compilation. In the chapters, you learned to create fresh Managed C++ applications. But, can you
only create a managed application from scratch? If not, then what happens to the existing unmanaged applications? Imagine re-creating those enormous applications. Obviously, you wouldn’t choose to do a complete migration. Instead, you would want to implement selected functionality using Managed C++. To meet this end, Visual C++ .NET allows you to write an application that can be a mix of managed and unmanaged code. This appendix shows you how to migrate an unmanaged application to a managed application.
Sample Application
To illustrate the Visual C++ .NET feature just mentioned, I will be using a Win32 application. Following is the code of the Win32 application. Comment entries provide the required explanations.
//This is a simple application that contains a class with two member functions, GetStr and SetStr, a constructor, and a member variable defined in it. The functionality that this class exposes includes accepting a string, storing it in the class, retrieving the stored value, and displaying the value.
#include <iostream> using std::cout; using std::endl;
//unmanaged C++ class definition
class CDisplayString
{
public:
CDisplayString(char *);
char * GetStr(void);
void SetStr(char *);
private:
char * m_str;
