VC++ Extensions Header in Detail

See Also   

The following header, icrsint.h, details the interfaces that allow clients to fetch a row of data directly into class data members. Clients need to include binding entries in their class to specify the association between a Recordset Field object and a class data member.

#ifndef _ICRSINT_H_
#define _ICRSINT_H_

#include <olectl.h>
#include <stddef.h>

// forwards
class CADORecordBinding;

#define classoffset(base, derived) \
   ((DWORD)(static_cast<base*>((derived*)8))-8)

enum FieldStatusEnum
{   
   adFldOK = 0,
   adFldBadAccessor = 1,
   adFldCantConvertValue = 2,
   adFldNull = 3,
   adFldTruncated = 4,
   adFldSignMismatch = 5,
   adFldDataOverFlow = 6,
   adFldCantCreate = 7,
   adFldUnavailable = 8,
   adFldPermissionDenied = 9,
   adFldIntegrityViolation = 10,
   adFldSchemaViolation = 11,
   adFldBadStatus = 12,
   adFldDefault = 13
};

typedef struct stADO_BINDING_ENTRY
{
   ULONG         ulOrdinal;
    WORD         wDataType;
   BYTE         bPrecision;
   BYTE         bScale;
   ULONG         ulSize;
   ULONG         ulOffSet;
   ULONG         ulIADOBindingEntriesOffSet;
   ULONG         ulFldStatusOffset;
   BOOL         fModify;
} ADO_BINDING_ENTRY;

#define BEGIN_ADO_BINDING(cls) public: \
   typedef cls ADORowClass; \
   const ADO_BINDING_ENTRY* STDMETHODCALLTYPE GetADOBindingEntries() { \
   static const ADO_BINDING_ENTRY rgADOBindingEntries[] = { 

#define ADO_FIXED_LENGTH_BINDING_ENTRY(Ordinal, DataType, Buffer, \   Status, Modify)\
   {Ordinal, \
   DataType, \
   0, \
   0, \
   0, \
   offsetof(ADORowClass, Buffer), \
   classoffset(CADORecordBinding, ADORowClass), \
   offsetof(ADORowClass, Status), \
   Modify},

#define ADO_NUMERIC_BINDING_ENTRY(Ordinal, DataType, \
   Buffer, Precision, Scale, Status, Modify)\
   {Ordinal, \
   DataType, \
   Precision, \
   Scale, \
   0, \
   offsetof(ADORowClass, Buffer), \
   classoffset(CADORecordBinding, ADORowClass), \
   offsetof(ADORowClass, Status), \
   Modify},

#define ADO_VARIABLE_LENGTH_BINDING_ENTRY(Ordinal, DataType, \
   Buffer, Size, Status, Modify)\
   {Ordinal, \
   DataType, \
   0, \
   0, \
   Size, \
   offsetof(ADORowClass, Buffer), \
   classoffset(CADORecordBinding, ADORowClass), \
   offsetof(ADORowClass, Status), \
   Modify},

#define END_ADO_BINDING() {0, adEmpty, 0, 0, 0, 0, 0, adFldOK, FALSE}};\
   return rgADOBindingEntries;}

//
// Interface that the client 'record' class needs to support. 
// The ADO Binding entries provide the implementation for this interface.
//
class CADORecordBinding
{
public:
   STDMETHOD_(const ADO_BINDING_ENTRY*, GetADOBindingEntries) 
   (VOID) PURE;
};

//
// Interface that allows a client to fetch a record of data into 
// class data members.
//
DEFINE_GUID(IID_IADORecordBinding, 
            0x00000544, 0, 0x10, 0x80,0,0,0xAA,0,0x6D,0x2E,0xA4);
DECLARE_INTERFACE_(IADORecordBinding, IUnknown)
{
public:
   STDMETHOD(BindToRecordset)(CADORecordBinding *pAdoRecordBinding)PURE;
   STDMETHOD(AddNew)(CADORecordBinding *pAdoRecordBinding) PURE;
   STDMETHOD(Update)(CADORecordBinding *pAdoRecordBinding) PURE;
};

#endif // !_ICRSINT_H_