Since 1.7.7.x version of SDKs you can create objects in external processes. This is useful to increase a stability of your application.
For example, when you work with flash items in Character Generator the items might be memory-consuming (a well-known problem of SWF animation). And if overall memory usage is higher than system limits, the whole application might hang or crash. To avoid this problem, there is a way to create an object (in this example, Character Generator) in an external process. So if something goes wrong, it is only the external process that experiences problems and you can delete the process without any harm to your main application. If necessary, you can create a new instance of the object in a new external process. For instance, to restore the graphics overlay.
All the process is operated by IMFCreator interface of MFFactory object both in MFormats and MPlatform SDKs.
Create an object in an external process
For this, you should create an MFFactory object and use MFExternalCreate method. You need a GUID of an object you'd like to create. You can find GUIDs of objects in IDL files included in /Include folders of your SDK's directory. For example, GUID of Character Generator is "0F56D2E7-033C-4A05-BCDA-DF58C9BBF06F".
MFFactoryClass m_objMFFactory = new MFFactoryClass(); uint m_dwProcessID; // Process ID for a new process Guid gCG_CLSID = new Guid( "{0F56D2E7-033C-4A05-BCDA-DF58C9BBF06F}" ); // GUID of a target type object pCG_Unk; // output object itself m_objMFFactory.MFExternalCreate(gCG_CLSID, out pCG_Unk, out m_dwProcessID, "");
It returns you an object that you should cast to a required interface or class before use it further:
IMLCharGen m_pCharGen = (IMLCharGen)pCG_Unk; // cast the result object to a required interface
And the next step is to use the object:
mySourceObject.PluginsAdd(m_pCharGen, 0);
Manage the object from the main application
Once created, you can get a state of the object from your main code. To get info whether the object is alive, you should use MFExternalIsAliveByPID method. The method returns you whether the external object is alive (returns 1) or not (returns 0). You should use the process ID you've received the moment you created an object:
int bAlive = 0; m_objMFFactory.MFExternalIsAliveByPID(m_dwProcessID, out bAlive );
You can destroy the external process if something is wrong with it with MFExternalDestroy method. For this method, you need an object that you've created with the MFExternalCreate:
m_objMFFactory.MFExternalDestroy(pCG_Unk);