Basic Interface


FUnknown

Inheritance: none
Include File:  funknown.h

The FUnknown::queryInterface method is used to retrieve pointers to other interfaces of the object. FUnknown::addRef and FUnknown::release manage the lifetime of the object. If no more references exist, the object is destroyed in memory.

Interfaces are identified by 16 byte Globally Unique Identifiers. The SDK provides a class called FUID for this purpose.

Methods:


FUnknown::queryInterface

tresult PLUGIN_API queryInterface (const char* iid, void** obj)

Query for a pointer to the specified interface. Returns kResultOk on success or kNoInterface if the object does not implement the interface. The object has to call addRef when returning an interface.

Parameters:

iid 16 Byte interface identifier (-> FUID)
obj On return, obj should point to the requested interface


FUnknown::addRef

unsigned long PLUGIN_API addRef ()

Add a reference and return the new reference count.

Remarks:

The initial reference count after creating an object is 1.


FUnknown::release

unsigned long PLUGIN_API release ()

Release a reference and return the new reference count. If the reference count reaches zero, the object has to be destroyed in memory.


HOWTO 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 IPluginBase,
			public IPlugController,
			public IEditorFactory
{
public:
	DECLARE_FUNKNOWN_METHODS

	// declare the methods of all inherited interfaces here...
};


tresult CMyMultiClass::queryInterface (const char* iid, void** obj)
{
	QUERY_INTERFACE (iid, obj, ::FUnknown::iid, IPluginBase)
	QUERY_INTERFACE (iid, obj, IPluginBase::iid, IPluginBase)
	QUERY_INTERFACE (iid, obj, IPlugController::iid, IPlugController)
	QUERY_INTERFACE (iid, obj, IEditorFactory::iid, IEditorFactory)
	*obj = 0;
	return kNoInterface;
}


Last Modified: