Interface Technology Basics  VST 3.7
SDK for developing VST plug-in
How to derive a class from an interface

In the first example we derive a class directly from FUnknown, using some of the helper macros provided by the SDK.

class CMyClass: public FUnknown
{
public:
CMyClass ();
virtual ~CMyClass ();
DECLARE_FUNKNOWN_METHODS // declares queryInterface, addRef and release
};
CMyClass::CMyClass ()
{
FUNKNOWN_CTOR // init reference counter, increment global object counter
}
CMyClass::~CMyClass ()
{
FUNKNOWN_DTOR // decrement global object counter
}
IMPLEMENT_REFCOUNT (CMyClass) // implements reference counting
tresult CMyClass::queryInterface (const char* iid, void** obj)
{
QUERY_INTERFACE (iid, obj, ::FUnknown::iid, CMyClass)
return kNoInterface;
}

Developing a class with more than one interface is done by multiple inheritance. Additionally you have to provide an appropriate cast for each interface in the queryInterface method.

class CMyMultiClass : public Steinberg::IPluginBase,
public Steinberg::IPlugController,
public Steinberg::IEditorFactory
{
public:
// declare the methods of all inherited interfaces here...
};
IMPLEMENT_REFCOUNT (CMyMultiClass) // implements reference counting
tresult CMyMultiClass::queryInterface (const char* iid, void** obj)
{
QUERY_INTERFACE (iid, obj, Steinberg::FUnknown::iid, IPluginBase)
QUERY_INTERFACE (iid, obj, Steinberg::IPlugController::iid, IPlugController)
QUERY_INTERFACE (iid, obj, Steinberg::IEditorFactory::iid, IEditorFactory)
*obj = 0;
return kNoInterface;
}
Steinberg::tresult
int32 tresult
Definition: ftypes.h:76
DECLARE_FUNKNOWN_METHODS
#define DECLARE_FUNKNOWN_METHODS
Definition: funknown.h:85
QUERY_INTERFACE
#define QUERY_INTERFACE(iid, obj, InterfaceIID, InterfaceName)
Definition: funknown.h:127
Steinberg::FUnknown::iid
static const FUID iid
Definition: funknown.h:378
FUNKNOWN_DTOR
#define FUNKNOWN_DTOR
Definition: funknown.h:123
Steinberg::IPluginBase
Basic interface to a plug-in component: IPluginBase.
Definition: ipluginbase.h:36
FUNKNOWN_CTOR
#define FUNKNOWN_CTOR
Definition: funknown.h:118
Steinberg::IPluginBase::iid
static const FUID iid
Definition: ipluginbase.h:50
Steinberg::kNoInterface
Definition: funknown.h:188
IMPLEMENT_REFCOUNT
#define IMPLEMENT_REFCOUNT(ClassName)
Definition: funknown.h:102
Empty

Copyright ©2020 Steinberg Media Technologies GmbH. All Rights Reserved. This documentation is under this license.