Declare Serial Mfc

Declare Serial Mfc

Declare Serial Mfc Rating: 3,7/5 3134 votes
-->

Using CObject.; 2 minutes to read +2; In this article. CObject is the root base class for most of the Microsoft Foundation Class Library (MFC). The CObject class contains many useful features that you may want to incorporate into your own program objects, including serialization support, run-time class information, and object diagnostic output. If you derive your class from CObject. I am working on a project to get thumbwheel switches on a SOFLAM to interface with an arduino and then send the data to a C MFC plugin over serial. There are three thumbwheel switches that are 0-9. I need the arduino to send the 'three digit code' to the computer over serial. This is where I am getting my headaches.

The classes CObject and CRuntimeClass encapsulate several object services, including access to run-time class information, serialization, and dynamic object creation. All classes derived from CObject inherit this functionality.

Access to run-time class information enables you to determine information about an object's class at run time. The ability to determine the class of an object at run time is useful when you need extra type-checking of function arguments and when you must write special-purpose code based on the class of an object. Run-time class information is not supported directly by the C++ language.

Serialization is the process of writing or reading an object's contents to or from a file. You can use serialization to store an object's contents even after the application exits. The object can then be read from the file when the application is restarted. Such data objects are said to be 'persistent.'

Dynamic object creation enables you to create an object of a specified class at run time. For example, document, view, and frame objects must support dynamic creation because the framework needs to create them dynamically.

The following table lists the MFC macros that support run-time class information, serialization, and dynamic creation.

For more information on these run-time object services and serialization, see the article CObject Class: Accessing Run-Time Class Information.

Run-Time Object Model Services Macros

DECLARE_DYNAMICEnables access to run-time class information (must be used in the class declaration).
DECLARE_DYNCREATEEnables dynamic creation and access to run-time class information (must be used in the class declaration).
DECLARE_SERIALEnables serialization and access to run-time class information (must be used in the class declaration).
IMPLEMENT_DYNAMICEnables access to run-time class information (must be used in the class implementation).
IMPLEMENT_DYNCREATEEnables dynamic creation and access to run-time information (must be used in the class implementation).
IMPLEMENT_SERIALPermits serialization and access to run-time class information (must be used in the class implementation).
RUNTIME_CLASSReturns the CRuntimeClass structure that corresponds to the named class.

OLE frequently requires the dynamic creation of objects at run time. For example, an OLE server application must be able to create OLE items dynamically in response to a request from a client. Similarly, an automation server must be able to create items in response to requests from automation clients.

The Microsoft Foundation Class Library provides two macros specific to OLE.

Dynamic Creation of OLE Objects

AFX_COMCTL32_IF_EXISTSDetermines whether the Common Controls library implements the specified API.
AFX_COMCTL32_IF_EXISTS2Determines whether the Common Controls library implements the specified API.
DECLARE_OLECREATEEnables objects to be created through OLE automation.
DECLARE_OLECTLTYPEDeclares the GetUserTypeNameID and GetMiscStatus member functions of your control class.
DECLARE_PROPPAGEIDSDeclares that the OLE control provides a list of property pages to display its properties.
IMPLEMENT_OLECREATEEnables objects to be created by the OLE system.
IMPLEMENT_OLECTLTYPEImplements the GetUserTypeNameID and GetMiscStatus member functions of your control class.
IMPLEMENT_OLECREATE_FLAGSEither this macro or IMPLEMENT_OLECREATE must appear in the implementation file for any class that uses DECLARE_OLECREATE.

AFX_COMCTL32_IF_EXISTS

Determines whether the Common Controls library implements the specified API.

Syntax

Parameters

proc
Pointer to a null-terminated string containing the function name, or specifies the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero. This parameter must be in Unicode.

Remarks

Use this macro to determine whether the Common Controls library the function specified by proc (instead of calling GetProcAddress.

Requirements

afxcomctl32.h, afxcomctl32.inl

AFX_COMCTL32_IF_EXISTS2

Determines whether the Common Controls library implements the specified API (this is the Unicode version of AFX_COMCTL32_IF_EXISTS).

Syntax

Parameters

proc
Pointer to a null-terminated string containing the function name, or specifies the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero. This parameter must be in Unicode.

Remarks

Use this macro to determine whether the Common Controls library the function specified by proc (instead of calling GetProcAddress. This macro is the Unicode version of AFX_COMCTL32_IF_EXISTS.

Requirements

afxcomctl32.h, afxcomctl32.inl

DECLARE_DYNAMIC

Adds the ability to access run-time information about an object's class when deriving a class from CObject.

Parameters

class_name
The actual name of the class.

Remarks

Add the DECLARE_DYNAMIC macro to the header (.h) module for the class, then include that module in all .cpp modules that need access to objects of this class.

If you use the DECLARE_ DYNAMIC and IMPLEMENT_DYNAMIC macros as described, you can then use the RUNTIME_CLASS macro and the CObject::IsKindOf function to determine the class of your objects at run time.

If DECLARE_DYNAMIC is included in the class declaration, then IMPLEMENT_DYNAMIC must be included in the class implementation.

For more information on the DECLARE_DYNAMIC macro, see CObject Class Topics.

Example

See the example for IMPLEMENT_DYNAMIC.

Requirements

Header: afx.h

DECLARE_DYNCREATE

Enables objects of CObject-derived classes to be created dynamically at run time.

Parameters

class_name
The actual name of the class.

Remarks

The framework uses this ability to create new objects dynamically. For example, the new view created when you open a new document. Document, view, and frame classes should support dynamic creation because the framework needs to create them dynamically.

Add the DECLARE_DYNCREATE macro in the .h module for the class, then include that module in all .cpp modules that need access to objects of this class.

If DECLARE_DYNCREATE is included in the class declaration, then IMPLEMENT_DYNCREATE must be included in the class implementation.

For more information on the DECLARE_DYNCREATE macro, see CObject Class Topics.

Note

The DECLARE_DYNCREATE macro includes all the functionality of DECLARE_DYNAMIC.

Example

See the example for IMPLEMENT_DYNCREATE.

Requirements

Header: afx.h

DECLARE_OLECTLTYPE

Declares the GetUserTypeNameID and GetMiscStatus member functions of your control class.

Syntax

Parameters

class_name
The name of the control class.

Remarks

GetUserTypeNameID and GetMiscStatus are pure virtual functions, declared in COleControl. Because these functions are pure virtual, they must be overridden in your control class. In addition to DECLARE_OLECTLTYPE, you must add the IMPLEMENT_OLECTLTYPE macro to your control class declaration.

Requirements

Header: afxctl.h

DECLARE_PROPPAGEIDS

Declares that the OLE control provides a list of property pages to display its properties.

Declare Serial Mfc

Syntax

Parameters

class_name
The name of the control class that owns the property pages.

Remarks

Use the DECLARE_PROPPAGEIDS macro at the end of your class declaration. Then, in the .cpp file that defines the member functions for the class, use the BEGIN_PROPPAGEIDS macro, macro entries for each of your control's property pages, and the END_PROPPAGEIDS macro to declare the end of the property page list.

For more information on property pages, see the article ActiveX Controls: Property Pages.

Implement_serial

Requirements

Header: afxctl.h

DECLARE_SERIAL

Generates the C++ header code necessary for a CObject-derived class that can be serialized.

Parameters

class_name
The actual name of the class.

Remarks

Serialization is the process of writing or reading the contents of an object to and from a file.

Use the DECLARE_SERIAL macro in an .h module, and then include that module in all .cpp modules that need access to objects of this class.

If DECLARE_SERIAL is included in the class declaration, then IMPLEMENT_SERIAL must be included in the class implementation.

The DECLARE_SERIAL macro includes all the functionality of DECLARE_DYNAMIC and DECLARE_DYNCREATE.

You can use the AFX_API macro to automatically export the CArchive extraction operator for classes that use the DECLARE_SERIAL and IMPLEMENT_SERIAL macros. Bracket the class declarations (located in the .h file) with the following code:

For more information on the DECLARE_SERIAL macro, see CObject Class Topics.

Example

Requirements

Header: afx.h

IMPLEMENT_DYNAMIC

Generates the C++ code necessary for a dynamic CObject-derived class with run-time access to the class name and position within the hierarchy.

Parameters

class_name
The actual name of the class.

base_class_name
The name of the base class.

Remarks

Use the IMPLEMENT_DYNAMIC macro in a .cpp module, and then link the resulting object code only once.

For more information, see CObject Class Topics.

Example

Requirements

Header: afx.h

IMPLEMENT_DYNCREATE

Enables objects of CObject-derived classes to be created dynamically at run time when used with the DECLARE_DYNCREATE macro.

Parameters

class_name
The actual name of the class.

base_class_name
The actual name of the base class.

Remarks

The framework uses this ability to create new objects dynamically, for example, when it reads an object from disk during serialization. Add the IMPLEMENT_DYNCREATE macro in the class implementation file. For more information, see CObject Class Topics.

If you use the DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros, you can then use the RUNTIME_CLASS macro and the CObject::IsKindOf member function to determine the class of your objects at run time.

If DECLARE_DYNCREATE is included in the class declaration, then IMPLEMENT_DYNCREATE must be included in the class implementation.

Note that this macro definition will invoke the default constructor for your class. If a non-trivial constructor is explicitly implemented by the class, it must also explicitly implement the default constructor as well. The default constructor can be added to the class's private or protected member sections to prevent it from being called from outside the class implementation.

Example

Requirements

Header: afx.h

IMPLEMENT_OLECREATE_FLAGS

Either this macro or IMPLEMENT_OLECREATE must appear in the implementation file for any class that uses DECLARE_OLECREATE.

Syntax

Parameters

class_name
The actual name of the class.

external_name
The object name exposed to other applications (enclosed in quotation marks).

nFlags
Contains one or more of the following flags:

  • afxRegInsertable Allows the control to appear in the Insert Object dialog box for OLE objects.

  • afxRegApartmentThreading Sets the threading model in the registry to ThreadingModel=Apartment.

  • afxRegFreeThreading Sets the threading model in the registry to ThreadingModel=Free.

l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8Components of the class's CLSID.

Remarks

Note

If you use IMPLEMENT_OLECREATE_FLAGS, you can specify which threading model your object supports by using the nFlags parameter. If you want to support only the single-treading model, use IMPLEMENT_OLECREATE.

The external name is the identifier exposed to other applications. Client applications use the external name to request an object of this class from an automation server.

The OLE class ID is a unique 128-bit identifier for the object. It consists of one long, two WORDs, and eight BYTEs, as represented by l, w1, w2, and b1 through b8 in the syntax description. The Application Wizard and code wizards create unique OLE class IDs for you as required.

Requirements

Header: afxdisp.h

IMPLEMENT_OLECTLTYPE

Implements the GetUserTypeNameID and GetMiscStatus member functions of your control class.

Syntax

Parameters

class_name
The name of the control class.

idsUserTypeName
The resource ID of a string containing the external name of the control.

dwOleMisc
An enumeration containing one or more flags. For more information on this enumeration, see OLEMISC in the Windows SDK.

Remarks

In addition to IMPLEMENT_OLECTLTYPE, you must add the DECLARE_OLECTLTYPE macro to your control class declaration.

The GetUserTypeNameID member function returns the resource string that identifies your control class. GetMiscStatus returns the OLEMISC bits for your control. This enumeration specifies a collection of settings describing miscellaneous characteristics of your control. For a full description of the OLEMISC settings, see OLEMISC in the Windows SDK.

Note

The default settings used by the ActiveX ControlWizard are: OLEMISC_ACTIVATEWHENVISIBLE, OLEMISC_SETCLIENTSITEFIRST, OLEMISC_INSIDEOUT, OLEMISC_CANTLINKINSIDE, and OLEMISC_RECOMPOSEONRESIZE.

Requirements

Header: afxctl.h

IMPLEMENT_SERIAL

Generates the C++ code necessary for a dynamic CObject-derived class with run-time access to the class name and position within the hierarchy.

Parameters

class_name
The actual name of the class.

base_class_name
The name of the base class.

wSchema
A UINT 'version number' that will be encoded in the archive to enable a deserializing program to identify and handle data created by earlier program versions. The class schema number must not be -1.

Remarks

Use the IMPLEMENT_SERIAL macro in a .cpp module; then link the resulting object code only once.

You can use the AFX_API macro to automatically export the CArchive extraction operator for classes that use the DECLARE_SERIAL and IMPLEMENT_SERIAL macros. Bracket the class declarations (located in the .h file) with the following code:

For more information, see the CObject Class Topics.

Example

Requirements

Header: afx.h

RUNTIME_CLASS

Gets the run-time class structure from the name of a C++ class.

Parameters

class_name
The actual name of the class (not enclosed in quotation marks).

Remarks

RUNTIME_CLASS returns a pointer to a CRuntimeClass structure for the class specified by class_name. Only CObject-derived classes declared with DECLARE_DYNAMIC, DECLARE_DYNCREATE, or DECLARE_SERIAL will return pointers to a CRuntimeClass structure.

For more information, see CObject Class Topics.

Example

Requirements

Header: afx.h

DECLARE_OLECREATE

Enables objects of CCmdTarget-derived classes to be created through OLE automation.

Parameters

class_name
The actual name of the class.

Remarks

This macro enables other OLE-enabled applications to create objects of this type.

Add the DECLARE_OLECREATE macro in the .h module for the class, and then include that module in all .cpp modules that need access to objects of this class.

If DECLARE_OLECREATE is included in the class declaration, then IMPLEMENT_OLECREATE must be included in the class implementation. A class declaration using DECLARE_OLECREATE must also use DECLARE_DYNCREATE or DECLARE_SERIAL.

Requirements

Header: afxdisp.h

IMPLEMENT_OLECREATE

Either this macro or IMPLEMENT_OLECREATE_FLAGS must appear in the implementation file for any class that uses DECLARE_OLECREATE.

Parameters

class_name
The actual name of the class.

external_name
The object name exposed to other applications (enclosed in quotation marks).

l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8Components of the class's CLSID.

Remarks

Note

If you use IMPLEMENT_OLECREATE, by default, you support only the single threading model. If you use IMPLEMENT_OLECREATE_FLAGS, you can specify which threading model your object supports by using the nFlags parameter.

The external name is the identifier exposed to other applications. Client applications use the external name to request an object of this class from an automation server.

The OLE class ID is a unique 128-bit identifier for the object. It consists of one long, two WORDs, and eight BYTEs, as represented by l, w1, w2, and b1 through b8 in the syntax description. The Application Wizard and code wizards create unique OLE class IDs for you as required.

The Apocalyptic Gospel: Mystery, Revelation, and Common Sense - Kindle edition by Justin Mark Staller. Download it once and read it on your Kindle device, PC, phones or tablets. Use features like bookmarks, note taking and highlighting while reading The Apocalyptic Gospel: Mystery, Revelation, and Common Sense. Mystery revelation ebook download. Download your free eBook on Revelation and go deeper into the prophecies of chapter 13 and 17. This offer is a gift to you at no cost for a limited time! Mystery of the book of revelation and daniel Download mystery of the book of revelation and daniel or read online books in PDF, EPUB, Tuebl, and Mobi Format. Click Download or Read Online button to get mystery of the book of revelation and daniel book now. This site is like a library, Use search box in the widget to get ebook that you want.

Requirements

Header: afxdisp.h

See also

Macros and Globals
Isolation of the MFC Common Controls Library
CLSID Key

Declare Serial Mfc
© 2020