Table of contents
1.
Introduction
2.
Data Transfer Classes
2.1.
IDataObjectImpl Class
2.1.1.
Syntax
2.1.2.
Public Methods
2.2.
CBindStatusCallback Class
2.2.1.
Syntax
2.2.2.
Members
2.2.3.
Public Methods
3.
Frequently Asked Questions
3.1.
What is a DTO class?
3.2.
What does ATL stand for?
3.3.
What is a class data value?
3.4.
Why do we need ATL?
3.5.
List the difference between class and instance.
4.
Conclusion
Last Updated: Mar 27, 2024

Data transfer 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. This data is represented by the Data Transfer Classes.

These classes are public (or static) classes with no methods.

Data Transfer Classes

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

Data Transfer Classes

The data transfer class is a static class in the Active Template Library (ATL) that transports the data between the subsystems. The main 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 classes

Let's now discuss some examples of Data transfer classes.

IDataObjectImpl Class

This class supports Uniform Data Transfer (UDP) using standard formats and methods to retrieve and set data. IDataObjectImpl Class manages connections and changes notifications to advise sinks.

Syntax

template<class T>
class IDataObjectImpl

Here, T is your class, derived from IDataObjectImpl.

Public Methods

Name  Description Syntax
IDataObjectImpl::DAdvise By using this method, a link is created between the advice sink and the data object. This makes it possible for the advice sink to be notified of changes to the object.

HRESULT DAdvise(

    FORMATETC* pformatetc,

    DWORD advf,

    IAdviseSink* pAdvSink,

    DWORD* pdwConnection);

 

IDataObjectImpl::DUnadvise Terminates a connection that was previously established using DAdvise. HRESULT DUnadvise(DWORD dwConnection);
IDataObjectImpl::EnumDAdvise Builds an enumerator that may be used to loop through the current advisory connections.

HRESULT DAdvise(

    FORMATETC* pformatetc,

    DWORD advf,

    IAdviseSink* pAdvSink,

    DWORD* pdwConnection);

IDataObjectImpl::EnumFormatEtc Creates an enumerator that can loop through all the FORMATETC structures that the data object supports. Returns E_NOTIMPL from the ATL implementation.

HRESULT EnumFormatEtc(

    DWORD dwDirection,

    IEnumFORMATETC** ppenumFormatEtc);

 

IDataObjectImpl::FireDataChange It sends a change notification to every advice sink. HRESULT FireDataChange();
IDataObjectImpl::GetDataHere Similar to GetData, with the exception that the client must allocate the STGMEDIUM structure. E NOTIMPL is the result of the ATL implementation.

HRESULT GetDataHere(

    FORMATETC* pformatetc,

    STGMEDIUM* pmedium);

 

IDataObjectImpl::QueryGetData Determines whether the data object is compatible with a specific FORMATETC data transfer structure. The ATL implementation returns the E_NOTIMPL. HRESULT QueryGetData(FORMATETC* pformatetc);
IDataObjectImpl::SetData

Transfer data to the data object from the client. 

E NOTIMPL is the result of the ATL implementation.

 

HRESULT SetData(

    FORMATETC* pformatetc,

    STGMEDIUM* pmedium,

    BOOL fRelease);

 

IDataObjectImpl::GetData Transfers data to the client from the data object. The data is sent over a STGMEDIUM structure after being described in a FORMATETC structure.

HRESULT GetData(

    FORMATETC* pformatetcIn,

    STGMEDIUM* pmedium);

 

CBindStatusCallback Class

This class carries out IBindStatusCallback interface implementation. It enables an asynchronous moniker to communicate with your object and transmit and receive information about asynchronous data transfers.

Syntax

template <class T,
   int nBindFlags = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_GETNEWESTVERSION | BINDF_NOWRITECACHE>
class ATL_NO_VTABLE CBindStatusCallback : public CComObjectRootEx <T ::_ThreadModel::ThreadModelNoCS>,
   public IBindStatusCallbackImpl<T>

Here,

T is your class containing the function that will be invoked as the data is received.

nBindFlags

Specifies the bind flags that GetBindInfo returns. The default implementation sets the binding asynchronous, retrieves the most recent version of the data/object, and does not keep the data it retrieves in the disc cache.

Members

Public Constructors

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

Public Methods

Name  Description Syntax
CBindStatusCallback::Download The static method that starts the downloading process creates a CBindStatusCallback object and calls StartAsyncDownload.

HRESULT DAdvise(

    FORMATETC* pformatetc,

    DWORD advf,

    IAdviseSink* pAdvSink,

    DWORD* pdwConnection);

 

CBindStatusCallback::GetBindInfo Requested by the asynchronous moniker to obtain details regarding the kind of bind that will be formed. HRESULT DUnadvise(DWORD dwConnection);
CBindStatusCallback::GetPriority Called by the asynchronous moniker to obtain the binding operation's priority. E_NOTIMPL is the result of the ATL implementation.

HRESULT DAdvise(

    FORMATETC* pformatetc,

    DWORD advf,

    IAdviseSink* pAdvSink,

    DWORD* pdwConnection);

CBindStatusCallback::OnDataAvailable Called to provide data to your application as it becomes available. Reads the data, then calls the function passed to it to use the data.

HRESULT EnumFormatEtc(

    DWORD dwDirection,

    IEnumFORMATETC** ppenumFormatEtc);

 

CBindStatusCallback::OnLowResource Called when resources are low. The ATL implementation returns S_OK. HRESULT FireDataChange();
CBindStatusCallback::OnObjectAvailable Called by the asynchronous moniker to pass an object interface pointer to your application. The ATL implementation returns S_OK.

HRESULT GetDataHere(

    FORMATETC* pformatetc,

    STGMEDIUM* pmedium);

 

CBindStatusCallback::OnProgress Called to indicate the progress of a data downloading process. The ATL implementation returns S_OK. HRESULT QueryGetData(FORMATETC* pformatetc);
CBindStatusCallback::OnStartBinding Called when the binding is started.

HRESULT SetData(

    FORMATETC* pformatetc,

    STGMEDIUM* pmedium,

    BOOL fRelease);

 

CBindStatusCallback::OnStopBinding Called when the asynchronous data transfer is stopped.

HRESULT GetData(

    FORMATETC* pformatetcIn,

    STGMEDIUM* pmedium);

 

Public Data Members

CBindStatusCallback::m_dwAvailableToRead Number of bytes available to read. DWORD m_dwAvailableToRead;
CBindStatusCallback::m_dwTotalRead Total number of bytes read. DWORD m_dwTotalRead;
CBindStatusCallback::m_pFunc Pointer to the function called when data is available. ATL_PDATAAVAILABLE m_pFunc;
CBindStatusCallback::m_pT Pointer to the object requesting the asynchronous data transfer. T* m_pT;

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 transfer classes and some examples of classes.

Check out the following articles to learn more about data transfer classes and 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