DATASRC.H

//-------------------------------------------------------------------- 
// Microsoft OLE DB Sample Provider
// (C) Copyright 1994 - 1996 Microsoft Corporation. All Rights Reserved.
//
// @doc
//
// @module DATASRC.H | CDataSource base object and contained interface
// definitions
//
//
#ifndef _DATASRC_H_
#define _DATASRC_H_



// Forward declarations ------------------------------------------------------

class CImpIDBInitialize;
class CImpIDBProperties;
classCImpIDBInfo;
class CImpIDBCreateSession;
classCDataSource;

typedef CImpIDBInitialize* PIMPIDBINITIALIZE;
typedef CImpIDBProperties* PIMPIDBProperties;
typedef CImpIDBInfo*PIMPIDBINFO;
typedef CImpIDBCreateSession* PIMPIDBCREATESESSION;
typedef CDataSource*PCDATASOURCE;


// For common dialog browsing directories
typedef struct tagBROWSEINFO
{
OPENFILENAME*lpofn; // Pointer to OPENFILENAME
UINTuFileOkString; // FILEOKSTRING message
LPCSTRszPrompt;// Prompt text, NULL if not required
} BROWSEINFO, * lpBROWSEINFO;

// Classes -------------------------------------------------------------------

//----------------------------------------------------------------------------
// @class CDataSource | Containing class for all interfaces on the Datasource
// CoType Object
//
class CDataSource : public IUnknown//@base public | IUnknown
{
//Contained interfaces are friends
friend class CImpIDBInitialize;
friend class CImpIDBInfo;
friend class CImpIDBProperties;
friend class CImpIDBCreateSession;
friend class CDBSession;

protected: //@access protected
//@cmember Reference count
ULONGm_cRef;
//@cmember Path Name
charm_szPath[MAX_PATH];
//@member flag == TRUE if this Data Source object is an an initialized state
BOOL m_fDSOInitialized;
//@member flag == TRUE if DBSession object has been created
BOOL m_fDBSessionCreated;
//@member Utility object to manage properties
PCUTILPROP m_pUtilProp;
//@cmember Controlling IUnknown
LPUNKNOWNm_pUnkOuter;
//@cmember Contained IDBInitialize
PIMPIDBINITIALIZEm_pIDBInitialize;
//@cmember Contained IDBProperties
PIMPIDBProperties m_pIDBProperties;
//@cmember Contained IDBInfo
PIMPIDBINFOm_pIDBInfo;
//@member contained IDBCreateSession
PIMPIDBCREATESESSION m_pIDBCreateSession;

public: //@access public
//@cmember Constructor
CDataSource(LPUNKNOWN);
//@cmember Destructor
~CDataSource(void);

//@cmember Intitialization Routine
BOOL FInit(void);

//Object's base IUnknown
//@cmember Request an Interface
STDMETHODIMPQueryInterface(REFIID, LPVOID *);
//@cmember Increments the Reference count
STDMETHODIMP_(ULONG)AddRef(void);
//@cmember Decrements the Reference count
STDMETHODIMP_(ULONG)Release(void);
//@cmember Set the DBSessionCreated flag to FALSE
inline VOIDRemoveSession(void)
{ m_fDBSessionCreated = FALSE;};
};

typedef CDataSource *PCDATASOURCE;


//----------------------------------------------------------------------------
// @class CImpIDBInitialize | Contained IDBInitialize class
//
class CImpIDBInitialize : public IDBInitialize//@base public | IDBInitialize
{
private: //@access private
DEFINE_DEFAULT_IUNKNOWN_MEMBER_DATA(CDataSource)

public: //@access public
DEFINE_DEFAULT_IUNKNOWN_CTOR_DTOR(CDataSource, CImpIDBInitialize);
DEFINE_DEFAULT_IUNKNOWN_ADDREF_RELEASE

//IDBInitialize members
//@cmember Initialize Method
STDMETHODIMPInitialize(void);
//@cmember Uninitialize Method
STDMETHODIMP Uninitialize(void);
};



//----------------------------------------------------------------------------------------
// @class CImpIDBCreateSession | contained IDBCreateSession class


class CImpIDBCreateSession : public IDBCreateSession //@base public | IDBCreateSession
{
private: //@access private
DEFINE_DEFAULT_IUNKNOWN_MEMBER_DATA(CDataSource)

public: //@access public
DEFINE_DEFAULT_IUNKNOWN_CTOR_DTOR(CDataSource, CImpIDBCreateSession);
DEFINE_DEFAULT_IUNKNOWN_ADDREF_RELEASE

// IDBCreateSession method
//@cmember CreateSession method
STDMETHODIMP CreateSession( IUnknown*, REFIID, IUnknown** );
};



//----------------------------------------------------------------------------
// @class CImpIDBProperties | Contained IDBProperties class
//
class CImpIDBProperties : public IDBProperties//@base public | IDBProperties
{
private: //@access private
DEFINE_DEFAULT_IUNKNOWN_MEMBER_DATA(CDataSource)

public: //@access public
DEFINE_DEFAULT_IUNKNOWN_CTOR_DTOR(CDataSource, CImpIDBProperties);
DEFINE_DEFAULT_IUNKNOWN_ADDREF_RELEASE

//IDBProperties member functions

//@cmember GetProperties method
STDMETHODIMP GetProperties
(
ULONGcPropertySets,
const DBPROPIDSETrgPropertySets[],
ULONG* pcProperties,
DBPROPSET**prgProperties
);

//@cmember GetPropertyInfo method
STDMETHODIMP GetPropertyInfo
(
ULONGcPropertySets,
const DBPROPIDSETrgPropertySets[],
ULONG*pcPropertyInfoSets,
DBPROPINFOSET**prgPropertyInfoSets,
WCHAR**ppDescBuffer
);

//@cmember SetProperties method
STDMETHODIMPSetProperties
(
ULONGcProperties,
DBPROPSETrgProperties[]
);
};

//----------------------------------------------------------------------------
// @class CImpIDBInfo | Contained IDBInfo class
//
class CImpIDBInfo : public IDBInfo//@base public | IDBInfo
{
private: //@access private
DEFINE_DEFAULT_IUNKNOWN_MEMBER_DATA(CDataSource)

public: //@access public
DEFINE_DEFAULT_IUNKNOWN_CTOR_DTOR(CDataSource, CImpIDBInfo);
DEFINE_DEFAULT_IUNKNOWN_ADDREF_RELEASE

//IDBProperties member functions

//@cmember GetKeywords method
STDMETHODIMP GetKeywords
(
LPWSTR*ppwsKeywords
);

//@cmember GetLiteralInfo method
STDMETHODIMP GetLiteralInfo
(
ULONG cLiterals,
const DBLITERAL rgLiterals[ ],
ULONG* pcLiteralInfo,
DBLITERALINFO** prgLiteralInfo,
WCHAR** ppCharBuffer
);
};


// Support function for the Browse dialog
// in IDBInitialize::Initialize
void WINAPI CenterDialog(HWND hDlg);
UINT WINAPI CommDlgHook(HWND hDlg, UINTmsg, WPARAMwParam, LPARAM lParam);
BOOL WINAPI BrowseDirs(HWND hDlg, HINSTANCE hInst, LPCSTR lpszPrompt, LPSTR lpszDrive);

#endif