//--------------------------------------------------------------------
// Microsoft OLE DB Sample Provider
// (C) Copyright 1994 - 1996 Microsoft Corporation. All Rights Reserved.
//
// @doc
//
// @module SAMPPROV.H | Main include file
//
//
#ifndef _SAMPPROV_H_
#define _SAMPPROV_H_
// Defines -------------------------------------------------------------------
#ifdef DBINITCONSTANTS
#define GLOBAL_(type, name, val) type name = val
#else
#define GLOBAL_(type, name, val)extern type name
#endif
#define OBJECT_CONSTRUCTED()InterlockedIncrement(&g_cObj);
#define OBJECT_DESTRUCTED()InterlockedDecrement(&g_cObj);
#ifndef MAX
# define MIN(a,b) ( (a) < (b) ? (a) : (b) )
# define MAX(a,b) ( (a) > (b) ? (a) : (b) )
#endif
#ifndef NUMELEM
# define NUMELEM(x) (sizeof(x)/sizeof(*x))
#endif
#define MAX_HEAP_SIZE 128000
#define MAX_TOTAL_ROWBUFF_SIZE (10*1024*1024)// Max for all row buffers.
#define MAX_IBUFFER_SIZE 2000000
#define MAX_BIND_LEN (MAX_IBUFFER_SIZE/10)
#define STAT_ENDOFCURSOR 0x00000100// for forward-only means fully materialized
//-----------------------------------------------------------------------------
// Memory alignment
//-----------------------------------------------------------------------------
//++
// Useful rounding macros.
// Rounding amount is always a power of two.
//--
#define ROUND_DOWN( Size, Amount ) ((DWORD)(Size) & ~((Amount) - 1))
#define ROUND_UP( Size, Amount ) (((DWORD)(Size) + ((Amount) - 1)) & ~((Amount) - 1))
//++
// These macros are for aligment of ColumnData within the internal row buffer.
// COLUMN_ALIGN takes a ptr where you think data ought to go,
// and rounds up to the next appropriate address boundary.
//
// Rule of thumb is "natural" boundary, i.e. 4-byte member should be
// aligned on address that is multiple of 4.
//
// Most everything should be aligned to 32-bit boundary.
// But doubles should be aligned to 64-bit boundary, so let's play it safe.
// Also have __int64.
//--
// make these symbols a little easier to type\read
#if defined(_M_IX86)
# define X86
#elif defined(_M_MRX000)
# define MIPS
#elif defined(_M_ALPHA)
# define ALPHA
#elif defined(_M_PPC)
# define PPC
#else
# error: Unknown machine type: Not one of {X86,MIPS,ALPHA,PPC}.
#endif
#ifdef MIPS
# define COLUMN_ALIGNVAL 8
#elif defined(ALPHA)
# define COLUMN_ALIGNVAL 8
#else
# define COLUMN_ALIGNVAL 8// venerable 80x86
#endif
// Typedefs ------------------------------------------------------------------
typedef VOID**LPLPVOID;
typedef long int SDWORD;
typedef short int SWORD;
typedef unsigned long int UDWORD;
typedef unsigned short int UWORD;
typedef signed long SLONG;
typedef unsigned longULONG;
typedef unsigned shortUSHORT;
// Accessor Structure
typedef struct tagACCESSOR
{
DBACCESSORFLAGS dwAccessorFlags;
LONGcRef;
ULONGcBindings;
DBBINDINGrgBindings[1];
} ACCESSOR, *PACCESSOR;
//-----------------------------------------------------------------------------
// Macros for interface classes -- IUnknown methods and constructor\destructor
// Use these in the class definition for an interface.
// The code is defined in the header (definition) part because
// it is easier to do so here, and easier to use.
//
//
// @func void | DEFINE_DEFAULT_IUNKNOWN_MEMBER_DATA |
// Macro to define default IUnknown member data.
//
// @parm BaseClass | BaseClass | . | Class that is the OLE object.
//
// @ex Example usage|
//
//class CImpISomething : public ISomething {
//private:
//DEFINE_DEFAULT_IUNKNOWN_MEMBER_DATA(CSomethingBase)
//public:
//DEFINE_DEFAULT_IUNKNOWN_CTOR_DTOR(CSomethingBase, CImpISomething)
//DEFINE_DEFAULT_IUNKNOWN_ADDREF_RELEASE
//... implementation-specific methods ...
//};
//
#define DEFINE_DEFAULT_IUNKNOWN_MEMBER_DATA(BaseClass)\
DEBUGCODE(ULONG m_cRef);\
BaseClass*m_pObj;\
LPUNKNOWNm_pUnkOuter;
// @func void | DEFINE_DEFAULT_IUNKNOWN_CTOR_DTOR |
// Macro to define default IUnknown Ctor/Dtor.
//
// @parm BaseClass | BaseClass | . | Class that is the OLE object.
//
// @parm Any class | InterfaceClass | . | OLE interface class that this is part of.
#define DEFINE_DEFAULT_IUNKNOWN_CTOR_DTOR(BaseClass, InterfaceClass)\
InterfaceClass( BaseClass *pObj, IUnknown *pUnkOuter )\
{\
DEBUGCODE(m_cRef = 0L);\
m_pObj= pObj;\
m_pUnkOuter= pUnkOuter;\
}\
~InterfaceClass()\
{\
}
// @func void | DEFINE_DEFAULT_IUNKNOWN_ADDREF_RELEASE |
// Macro to define default IUnknown AddRef/Release.
#define DEFINE_DEFAULT_IUNKNOWN_ADDREF_RELEASE\
STDMETHODIMP_(ULONG)AddRef(void)\
{\
DEBUGCODE( ++m_cRef );\
return m_pUnkOuter->AddRef();\
}\
STDMETHODIMP_(ULONG)Release(void)\
{\
ASSERT( m_cRef > 0 );\
DEBUGCODE( --m_cRef );\
return m_pUnkOuter->Release();\
}\
STDMETHODIMPQueryInterface(REFIID riid, LPVOID *ppv)\
{\
return m_pUnkOuter->QueryInterface(riid, ppv);\
}
// Globals -------------------------------------------------------------------
GLOBAL_(LONG, g_cObj, 0L);// # of outstanding objects
GLOBAL_(LONG, g_cLock, 0L);// # of explicit locks set
GLOBAL_(DWORD, g_cAttachedProcesses, 0L);// # of attached processes
GLOBAL_(DWORD, g_dwPageSize, 0L);// System page size
GLOBAL_(IMalloc *, g_pIMalloc, NULL);// OLE2 task memory allocator
GLOBAL_(HINSTANCE, g_hInstance, 0L);// Instance Handle
GLOBAL_(IDataConvert *, g_pIDataConvert, NULL);// IDataConvert pointer
#endif