DG Kernel (ActiveX) Documentation


Skip Navigation Links.
Skip Navigation LinksHome Page > DG Kernel Controls > Programmatic Functionality > Generator Go to DGKC docs Search Documentation


Object Generator

Object Generator is an object, which allow creation of other new objects. Object Generator is a sort of "new" operator similar to one of C#.

Using Object Generator

Object Generator implements IObjectGenerator_DG interface, which can be queried from IModel_DG, from IGlobalAPI_DG or from a standalone object as described in the Advanced section below.

IObjectGenerator_DG can be used to create new instances of objects. See details for types of available objects.

Advanced

To create a standalone instance of the Object Generator obtain IGlobalAPI_DG using a COM Api call CoGetClassObject(CLSID_KCGlobAPI, ..). See the example below. IObjectGenerator_DG can be obtained via a call to IGlobalAPI_DG.GetGenerator() like:

IGlobalAPI_DGPtr Console::GetKcApi()
{
	LPCLASSFACTORY pClf;
	HRESULT hr;
	// Use COM API call to Create Class Factory ( generic obejct constructor ) for KCAPI class
	if ((hr = ::CoGetClassObject(CLSID_KCGlobAPI, CLSCTX_INPROC_SERVER, nullptr, IID_IClassFactory, (void**)&pClf)) != NOERROR)
		return nullptr;
	IGlobalAPI_DG* iDgApi = nullptr;
	// Use the factory to create an object which implements IGlobalAPI_DG
	if (pClf->CreateInstance(nullptr, __uuidof(IGlobalAPI_DG), (void**)&iDgApi) != S_OK)
		return nullptr;
	pClf->Release();
	return IGlobalAPI_DGPtr(iDgApi);
}

IObjectGenerator_DGPtr Console::GetGenerator()
{
	IGlobalAPI_DGPtr iApi = GetKcApi();
	IObjectGenerator_DGPtr gen;
	iApi->GetGenerator(&gen);
	return gen;
}

bool Console::Init()
{
	m_gen = GetGenerator();
	m_gen->Create("IModel_DG", (IUnknown**)&m_iModel);
	//....
}

See Console sample for the full debuggable example.

See also Object Array sample.