📄 atlvcl.h
字号:
/////////////////////////////////////////////////////////////////////////////
// ATLVCL.H - Provides the connective tissue between
// the ATL framework and VCL components.
//
// $Revision: 1.75.1.0.1.0 $
// $Date: 28 Jun 2001 09:12:00 $
//
// Copyright (c) 1998,2000 Borland International
/////////////////////////////////////////////////////////////////////////////
#ifndef __ATLVCL_H_
#define __ATLVCL_H_
#pragma option push -VF
// These are required due to RTL differences between VC++ and BCB
//
#define _ATL_NO_FORCE_LIBS
#define _ATL_NO_DEBUG_CRT
// Defines _ASSERTE et al.
//
#include <utilcls.h>
// Delta for remapping messages for VCL compatibility
//
#if !defined(OCM_BASE)
#define OCM_BASE (int)(8192)
#endif
#if !defined(__ATLBASE_H)
#include <atl\atlbase.h>
#endif
#include <atl\atlmod.h>
#include <system.hpp>
#include <axctrls.hpp>
#include <objbase.h>
#include <sysutils.hpp>
#include <cguid.h>
#include <dir.h>
#include <safearry.h>
// Externs
// Pointer to save Initialization Procedure when using VCL
// (CBuilder3 backward compatibility)
//
extern void* SaveInitProc;
// Prototype of routines implemented in ATLVCL.CPP
//
bool __fastcall AutomationTerminateProc();
void __fastcall SaveVCLComponentToStream(TComponent *instance, LPSTREAM pStream);
void __fastcall LoadVCLComponentFromStream(TComponent *instance, LPSTREAM pStream);
TWinControl* CreateReflectorWindow(HWND parent, Controls::TControl* Control);
#if !defined(__ATLCOM_H__)
#include <atl\atlcom.h>
#endif
#include <shellapi.h>
#if !defined(__ATLCTL_H__)
#include <atl\atlctl.h>
#endif
#include <vcl.h>
#include <databkr.hpp>
#include <atl\axform.h>
// Forward type Declaration
//
template <class T> class DELPHICLASS TWinControlAccess;
// Forward function declarations
// (CBuilder3 backward compatibility)
//
void __fastcall InitAtlServer(void);
// Helper routines used by IMPL file of VCL ActiveX Controls
//
///////////////////////////////////////////////////////////////////////////////
// FONT property handlers
///////////////////////////////////////////////////////////////////////////////
inline void
SetVclCtlProp(Graphics::TFont* font, IFontDisp* fontdisp)
{
Axctrls::SetOleFont(font, fontdisp);
}
inline void
SetVclCtlProp(Graphics::TFont* font, IFontDispPtr fontdisp)
{
SetVclCtlProp(font, static_cast<IFontDisp*>(fontdisp));
}
// PUTREF version of FONT setter
inline void
SetVclCtlProp(Graphics::TFont* font, IFontDisp** fontdisp)
{
SetVclCtlProp(font, *fontdisp);
}
inline void
SetVclCtlProp(Graphics::TFont* font, IFontDispPtr* fontdisp)
{
SetVclCtlProp(font, *fontdisp);
}
inline void
GetVclCtlProp(Graphics::TFont* font, IFontDisp** fontdisp)
{
_di_IFontDisp _di_font;
Axctrls::GetOleFont(font, _di_font);
*fontdisp = _di_font;
if (*fontdisp)
(*fontdisp)->AddRef();
}
inline void
GetVclCtlProp(Graphics::TFont* font, IFontDispPtr* fontdisp)
{
GetVclCtlProp(font, reinterpret_cast<IFontDisp**>(fontdisp));
}
///////////////////////////////////////////////////////////////////////////////
// Picture property handlers
///////////////////////////////////////////////////////////////////////////////
inline void
GetVclCtlProp(TPicture* pic, IPictureDisp** ppPictDisp)
{
_di_IPictureDisp _di_picture;
Axctrls::GetOlePicture(pic, _di_picture);
*ppPictDisp = _di_picture;
if (*ppPictDisp)
(*ppPictDisp)->AddRef();
}
inline void
GetVclCtlProp(TPicture* pic, IPictureDispPtr* ppPictDisp)
{
GetVclCtlProp(pic, reinterpret_cast<IPictureDisp**>(ppPictDisp));
}
inline void
SetVclCtlProp(TPicture* pic, IPictureDisp* pPictDisp)
{
Axctrls::SetOlePicture(pic, pPictDisp);
}
inline void
SetVclCtlProp(TPicture* pic, IPictureDisp** ppPictDisp)
{
SetVclCtlProp(pic, *ppPictDisp);
}
inline void
SetVclCtlProp(TPicture* pic, IPictureDispPtr pPictDisp)
{
SetVclCtlProp(pic, static_cast<IPictureDisp*>(pPictDisp));
}
inline void
SetVclCtlProp(TPicture* pic, IPictureDispPtr* ppPictDisp)
{
SetVclCtlProp(pic, *ppPictDisp);;
}
///////////////////////////////////////////////////////////////////////////////
// Strings property handlers
///////////////////////////////////////////////////////////////////////////////
inline void
GetVclCtlProp(TStrings* str, IStrings **ppIString)
{
_di_IStrings _di_strings;
Axctrls::GetOleStrings(str, _di_strings);
*ppIString = _di_strings;
if (*ppIString)
(*ppIString)->AddRef();
}
inline void
GetVclCtlProp(TStrings* str, IStringsPtr *ppIString)
{
GetVclCtlProp(str, reinterpret_cast<IStrings**>(ppIString));
}
inline void
SetVclCtlProp(TStrings* str, IStrings* pIString)
{
Axctrls::SetOleStrings(str, pIString);
}
inline void
SetVclCtlProp(TStrings* str, IStrings** ppIString)
{
SetVclCtlProp(str, *ppIString);
}
inline void
SetVclCtlProp(TStrings* str, IStringsPtr pIString)
{
SetVclCtlProp(str, static_cast<IStrings*>(pIString));
}
inline void
SetVclCtlProp(TStrings* str, IStringsPtr* ppIString)
{
SetVclCtlProp(str, *ppIString);
}
/* IAppServer support */
/* IAppServerImpl is essentially Delphi's TRemoteDataModule; it implements
the IAppServer interface, and is used to publish datasets residing
in a TDataModule. Method calls on the IAppServer interface are
reflected to renamed methods of the style IAppServer_MethodName
in order to avoid ambiguity problems in multiply derived classes. */
template <class DM, class T , class Intf, const IID* piid, const GUID* plibid>
class ATL_NO_VTABLE IAppServerImpl: public IDispatchImpl<Intf, piid, plibid>
{
private:
TCOMCriticalSection m_CS;
public:
DM* m_DataModule; // The Core.
// Note: This data module _must_ descend from TCRemoteDataModule.
IAppServerImpl()
{
m_DataModule = new DM(NULL);
}
~IAppServerImpl()
{
m_DataModule->Free();
}
TCustomProvider* GetProvider(const AnsiString ProviderName)
{
return m_DataModule->GetProvider(ProviderName);
// assumes that DM derives from TCRDM.
}
void RegisterProvider(TCustomProvider* Provider)
{
m_DataModule->RegisterProvider(Provider);
}
void UnRegisterProvider(TCustomProvider* Provider)
{
m_DataModule->UnRegisterProvider(Provider);
}
// Reflector methods (forwarding shims)
// These methods lock and forward the call to methods on the
// exported providers. Exception handling is expected to be
// conducted by the function calling the reflector method.
HRESULT STDMETHODCALLTYPE IAppServer_AS_GetProviderNames(OleVariant &Result)
{
TCOMCriticalSection::Lock::Lock(m_CS);
Result = m_DataModule->CRDMGetProviderNames();
return S_OK;
// assumes that DM derives from TCRemoteDataModule.
}
HRESULT STDMETHODCALLTYPE IAppServer_AS_ApplyUpdates(WideString ProviderName,
System::OleVariant Delta, int MaxErrors, int& ErrorCount, OleVariant& OwnerData,
OleVariant& Result)
{
TCOMCriticalSection::Lock::Lock(m_CS);
Result = GetProvider(ProviderName)->ApplyUpdates(Delta, MaxErrors, ErrorCount, OwnerData);
return S_OK;
}
HRESULT STDMETHODCALLTYPE IAppServer_AS_GetRecords(const WideString ProviderName,
int Count, int& RecsOut, int Options, const WideString CommandText, OleVariant& Params,
OleVariant& OwnerData, OleVariant& Result)
{
TCOMCriticalSection::Lock::Lock(m_CS);
Result = GetProvider(ProviderName)->GetRecords(Count, RecsOut, Options, CommandText,
Params, OwnerData);
return S_OK;
}
HRESULT STDMETHODCALLTYPE IAppServer_AS_DataRequest(WideString ProviderName,
OleVariant Data, System::OleVariant& Result)
{
TCOMCriticalSection::Lock::Lock(m_CS);
Result = GetProvider(ProviderName)->DataRequest(Data);
return S_OK;
}
HRESULT STDMETHODCALLTYPE IAppServer_AS_RowRequest(const WideString ProviderName,
OleVariant Row, int RequestType, OleVariant& OwnerData, OleVariant& Result)
{
TCOMCriticalSection::Lock::Lock(m_CS);
Result = GetProvider(ProviderName)->RowRequest(Row, RequestType, OwnerData);
return S_OK;
}
HRESULT STDMETHODCALLTYPE IAppServer_AS_GetParams(const WideString ProviderName,
OleVariant& OwnerData, OleVariant& Result)
{
TCOMCriticalSection::Lock::Lock(m_CS);
Result = GetProvider(ProviderName)->GetParams(OwnerData);
return S_OK;
}
HRESULT STDMETHODCALLTYPE IAppServer_AS_Execute(const WideString ProviderName,
const WideString CommandText, OleVariant& Params, OleVariant& OwnerData)
{
TCOMCriticalSection::Lock::Lock(m_CS);
GetProvider(ProviderName)->Execute(CommandText, Params, OwnerData);
return S_OK;
}
// IAppServer implementation
// provides exception handling and forwards the call to a reflector
// method.
HRESULT STDMETHODCALLTYPE AS_GetProviderNames(OleVariant& Result)
{
ATLTRACE(_T("IAppServer::AS_GetProviderNames\n"));
HRESULT hres;
try
{
hres = static_cast<T*>(this)->IAppServer_AS_GetProviderNames(Result);
}
catch (Exception& e)
{
return (static_cast<T*>(this))->Error(e.Message.c_str());
}
return hres;
}
HRESULT STDMETHODCALLTYPE AS_ApplyUpdates (const WideString ProviderName,
const OleVariant Delta, int MaxErrors, int& ErrorCount, OleVariant& OwnerData,
OleVariant& Result)
{
ATLTRACE(_T("IAppServer::AS_ApplyUpdates\n"));
HRESULT hres;
try
{
hres = static_cast<T*>(this)->IAppServer_AS_ApplyUpdates(ProviderName, Delta,
MaxErrors, ErrorCount,
OwnerData, Result);
}
catch (Exception& e)
{
return(static_cast<T*>(this))->Error(e.Message.c_str());
}
return hres;
}
HRESULT STDMETHODCALLTYPE AS_GetRecords(const WideString ProviderName, int Count,
int &RecsOut, int Options, const WideString CommandText, OleVariant &Params,
OleVariant &OwnerData, OleVariant &Result)
{
ATLTRACE(_T("IAppServer::AS_GetRecords\n"));
HRESULT hres;
try
{
hres = static_cast<T*>(this)->IAppServer_AS_GetRecords(ProviderName, Count,
RecsOut, Options,
CommandText, Params,
OwnerData, Result);
}
catch (Exception& e)
{
return(static_cast<T*>(this))->Error(e.Message.c_str());
}
return hres;
}
HRESULT STDMETHODCALLTYPE AS_DataRequest(const WideString ProviderName, OleVariant Data,
OleVariant& Result)
{
ATLTRACE(_T("IAppServer::AS_DataRequest\n"));
HRESULT hres;
try
{
hres = static_cast<T*>(this)->IAppServer_AS_DataRequest(ProviderName, Data, Result);
}
catch (Exception& e)
{
return(static_cast<T*>(this))->Error(e.Message.c_str());
}
return hres;
}
HRESULT STDMETHODCALLTYPE AS_RowRequest(const WideString ProviderName,
OleVariant Row, int RequestType, OleVariant& OwnerData, OleVariant& Result)
{
ATLTRACE(_T("IAppServer::AS_RowRequest\n"));
HRESULT hres;
try
{
hres = static_cast<T*>(this)->IAppServer_AS_RowRequest(ProviderName, Row,
RequestType, OwnerData,
Result);
}
catch (Exception& e)
{
return(static_cast<T*>(this))->Error(e.Message.c_str());
}
return hres;
}
HRESULT STDMETHODCALLTYPE AS_GetParams(const WideString ProviderName, OleVariant& OwnerData,
OleVariant& Result)
{
ATLTRACE(_T("IAppServer::AS_GetParams\n"));
HRESULT hres;
try
{
hres = static_cast<T*>(this)->IAppServer_AS_GetParams(ProviderName, OwnerData, Result);
}
catch (Exception& e)
{
return(static_cast<T*>(this))->Error(e.Message.c_str());
}
return hres;
}
HRESULT STDMETHODCALLTYPE AS_Execute(const WideString ProviderName, const WideString CommandText,
OleVariant& Params, OleVariant& OwnerData)
{
ATLTRACE(_T("IAppServer::AS_GetParams\n"));
HRESULT hres;
try
{
hres = static_cast<T*>(this)->IAppServer_AS_Execute(ProviderName, CommandText,
Params, OwnerData);
}
catch (Exception& e)
{
return(static_cast<T*>(this))->Error(e.Message.c_str());
}
return hres;
}
/* Get Provider(const ProviderName: string); TCustomProvider; virtual;
}
/* IDataBroker support */
// IDataBrokerImpl class implements IDataBroker interface, and is
// used to publish datasets residing in a TDataModule.
/* IDataBroker was the interface exposed by TRemoteDataModule in MIDAS 2.0.
It is maintained here for backwards compatability, but has been deprecated. */
};
template <class DM, class T, class Intf, const IID* piid, const GUID* plibid>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -