Table of contents
1.
Introduction
2.
Data Types Classes
2.1.
CComBSTR 
2.1.1.
Syntax
2.1.2.
Public Constructors
2.1.3.
Public Methods
2.1.4.
Public Operators
2.1.5.
Public Data Members
2.2.
CComVariant Class
2.2.1.
Syntax
2.2.2.
Members
2.2.3.
Public Constructors
2.2.4.
Public Methods
2.2.5.
Public Operators
3.
CComCurrency 
3.1.
Syntax
3.2.
Public Constructors
3.3.
Public Methods
3.4.
Public data members
4.
Frequently Asked Questions
4.1.
What is a DTO class?
4.2.
What does ATL stand for?
4.3.
What is a class data value?
4.4.
Why do we need ATL?
4.5.
List the difference between class and instance.
5.
Conclusion
Last Updated: Mar 27, 2024

Data types classes

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The systems need to exchange data to communicate between two parts of a software system. The data types Classes represent this data. These classes are public (or static) classes with no methods. These classes wrap C++ data types.

Data types classes

Let's now briefly discuss Data Types Classes with some examples.

Data Types Classes

The data transfer class is a static class in the Active Template Library (ATL) that transports the data between the subsystems. The primary purpose of these classes is to reduce the amount of overhead created, which in turn will reduce the number of system calls needed between the subsystems.

Data types

 

CComBSTR 

Wraps the BSTR data type
 

Syntax

class CComBSTR

Public Constructors

Name  Description Syntax
CComBSTR::CComBSTR The constructor creates an object to receive notifications related to the asynchronous data transfer. For every bind operation, typically, one object is created. CBindStatusCallback();
CComBSTR::~CComBSTR The destructor frees all allocated resources. ~CBindStatusCallback();

 

Public Methods

Name  Description Syntax
CComBSTR::Append It appends a string(either lpsz or the BSTR member of bstrSrc ) to m_str. 

HRESULT Append(const CComBSTR& bstrSrc) throw();

HRESULT Append(wchar_t ch) throw();

HRESULT Append(char ch) throw();

HRESULT Append(LPCOLESTR lpsz) throw();

HRESULT Append(LPCSTR lpsz) throw();

HRESULT Append(LPCOLESTR lpsz, int nLen) throw();

CComBSTR::AppendBSTR Appends the specified BSTR to m_str. HRESULT AppendBSTR(BSTR p) throw();
CComBSTR::AppendBytes It appends the required number of bytes to m_str. HRESULT AppendBytes(const char* lpsz, int nLen) throw();
CComBSTR::ArrayToBSTR It creates a BSTR from the first character of each element in the safe array and attaches it to the CComBSTR object.

HRESULT ArrayToBSTR(const SAFEARRAY* pSrc) throw();

 

CComBSTR::AssignBSTR Assigns a BSTR to m_str. HRESULT AssignBSTR(const BSTR bstrSrc) throw();
CComBSTR::Attach It connects the BSTR to the CComBSTR object by setting up the m_str member to src.

void Attach(BSTR src) throw();

 

CComBSTR::BSTRToArray It creates a zero-based one-dimensional safearray,  where each array element is a character from the CComBSTR object. HRESULT BSTRToArray(LPSAFEARRAY* ppArray) throw();
CComBSTR::ByteLength Returns the length or number of m_str in bytes, excluding the terminating null character.

unsigned int ByteLength() const throw();

 

CComBSTR::Copy This constructor class allocates and returns a copy of m_str.  BSTR Copy() const throw();

 

Public Operators

CComBSTR::operator BSTR Casts a CComBSTR object to a BSTR. operator BSTR() const throw();
CComBSTR::operator ! Checks whether the BSTR string is NULL. bool operator!() const throw();
CComBSTR::operator != Returns the logical opposite of operator ==.

bool operator!= (const CComBSTR& bstrSrc) const throw();

bool operator!= (LPCOLESTR pszSrc) const;

bool operator!= (LPCSTR pszSrc) const;

bool operator!= (int nNull) const throw();

CComBSTR::operator & Returns the address of the BSTR stored in the m_str member. BSTR* operator&() throw();
CComBSTR::operator == Compares a CComBSTR with a string. CComBSTRs are compared textually in the context of the user's default locale.

bool operator== (const CComBSTR& bstrSrc) const throw();

bool operator== (LPCOLESTR pszSrc) const;

bool operator== (LPCSTR pszSrc) const;

bool operator== (int nNull) const throw();

Public Data Members

CComBSTR::m_str Contains the BSTR associated with the CComBSTR object. BSTR m_str;

CComVariant Class

This class wraps the VARIANT type, providing a member indicating the type of data stored.

Syntax

class CComVariant : public tagVARIANT

Members

Public Constructors

Name  Description Syntax
CComVariant::CComVariant It is the constructor. CBindStatusCallback();
CComVariant::~CComVariant The destructor that frees all allocated resources. ~CBindStatusCallback();

Public Methods

Name  Description Syntax
CComVariant::Attach Attaches a VARIANT to the CComVariant object.

HRESULT DAdvise(

HRESULT Attach(VARIANT* pSrc);

CComVariant::ChangeType Converts the CComVariant object to a new type. HRESULT ChangeType(VARTYPE vtNew, const VARIANT* pSrc = NULL);
CComVariant::Clear Clears the CComVariant object. HRESULT Clear();
CComVariant::Copy Copies a VARIANT to the CComVariant object. HRESULT Copy(const VARIANT* pSrc);
CComVariant::CopyTo Copies the contents of the CComVariant object. HRESULT CopyTo(BSTR* pstrDest);
CComVariant::Detach Detaches the underlying VARIANT from the CComVariant object. HRESULT Detach(VARIANT* pDest);
CComVariant::GetSize Returns the size in the number of bytes of the contents of the CComVariant object. ULONG GetSize() const;
CComVariant::ReadFromStream Loads a VARIANT from a stream. Sets the underlying VARIANT to the VARIANT contained in the specified stream. HRESULT ReadFromStream(IStream* pStream);
CComVariant::SetByRef Initializes the CComVariant object and sets the vt member to VT_BYREF. 

template < typename T >

void SetByRef(T* pT) throw();

CComVariant::WriteToStream Saves the underlying VARIANT to a stream. HRESULT WriteToStream(IStream* pStream);

Public Operators

CComVariant::operator < Indicates whether the CComVariant object is less than the specified VARIANT. bool operator<(const VARIANT& varSrc) const throw();
CComVariant::operator > Indicates whether the CComVariant object is greater than the specified VARIANT. bool operator>(const VARIANT& varSrc) const throw();
CComVariant::operator != Indicates whether the CComVariant object doesn't equal the specified VARIANT. bool operator!=(const VARIANT& varSrc) const throw();
CComVariant::operator == Indicates whether the CComVariant object equals the specified VARIANT.

bool operator==(const VARIANT& varSrc) const throw();

bool operator== (LPCOLESTR pszSrc) const;

bool operator== (LPCSTR pszSrc) const;

bool operator== (int nNull) const throw();

CComCurrency 

Includes methods and operators for creating and managing a CURRENCY object.

Syntax

class CComCurrency;

Public Constructors

Name  Description
CComCurrency::CComCurrency The constructor for a CComCurrency object.

Public Methods

Name  Description Syntax
CComCurrency::GetCurrencyPtr It returns the address of an m_currency data member. CURRENCY* GetCurrencyPtr() throw();
CComCurrency::GetFraction Call this method to get the fractional component of a CComCurrency object. SHORT GetFraction() const;
CComCurrency::GetInteger This method will return the integer component of a CComCurrency object. LONGLONG GetInteger() const;
CComCurrency::Round This method will round a CComCurrency object to the nearest integer value. HRESULT Roundint nDecimals);
CComCurrency::SetFraction It will set the fractional component of a CComCurrency object. HRESULT SetFraction(SHORT nFraction);
CComCurrency::SetInteger Call this method to set the integer component of a CComCurrency object. HRESULT SetInteger(LONGLONG nInteger);

Public data members

CComCurrency::m_currency The CURRENCY variable created by your class instance. The CURRENCY data member. CURRENCY m_currency;

Frequently Asked Questions

What is a DTO class?

Data Transfer Objects are public classes with no methods other than the compiler-supplied default constructor, having only public (static) fields limited to easily serializable types.

What does ATL stand for?

ATL stands for the active template library.

What is a class data value?

Information that is shared by all the instances or aggregate information about the instances is kept in a class data value.

Why do we need ATL?

We need ATL to provide efficient and easy-to-implement COM objects.

List the difference between class and instance.

The class is similar to the blueprint. The Object is a real item that was created using the "blueprint" (like the house). An instance represents an item that is virtual but not a true copy.

Conclusion

In this blog, we have discussed data types classes and some examples of various data types. Check out the following articles to learn more about data classes and data types.


To learn more about DSA, competitive coding, and many more knowledgeable topics, please look into the guided paths on Code Studio. Also, you can enroll in our courses and check out the mock test and problems available to you. Please check out our interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass