Share via


ISpObjectToken::CreateInstance (SAPI 5.3)

Microsoft Speech API 5.3

ISpObjectToken::CreateInstance

ISpObjectToken::CreateInstance creates an instance of an object.

  
    HRESULT CreateInstance(IUnknown   *pUnkOuter,
   DWORD       dwClsContext,
   REFIID      riid,
   void      **ppvObject
);

Parameters

  • pUnkOuter
    [in] If the object is being created as part of an aggregate, this is a pointer to the controlling IUnknown interface of the aggregate. Otherwise, pUnkOuter must be NULL.
  • dwClsContext
    [in] Context in which the code that manages the newly created object will run. It should be one of the following values:
    • CLSCTX_INPROC_SERVER
    • CLSCTX_INPROC_HANDLER
    • CLSCTX_LOCAL_SERVER
    • CLSCTX_REMOTE_SERVER
  • riid
    [in] Reference to the identifier of the interface used to communicate with the newly created object. If pUnkOuter is NULL, this parameter is frequently the IID of the initializing interface; if pUnkOuter is non-NULL, riid must be IID_IUnknown.
  • ppvObject
    [out, iid_is(riid)] Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, ppvObject contains the requested interface pointer. If the object does not support the interface specified in riid, the implementation must set ppvObject to NULL.

Return values

Value
S_OK
E_POINTER
E_INVALIDARG
SPERR_UNINITIALIZED
SPERR_TOKEN_DELETED
FAILED(hr)

Remarks

This method is used to create the underlying object that the object token represents. This method looks at the CLSID value stored in the object token and creates a COM object from this CLSID.

For example, when this method is called on an object token from the audio input category, an audio object that implements ISpStreamFormat will be created and returned.

This method is not used to create speech recognition or text-to-speech engines. Instead, an SpRecognizer or SpVoice object is created and the engine is then created by passing an object token to the ISpRecognizer::SetRecognizer or ISpVoice::SetVoicemethods.

Example

The following code snippet creates an InProc server instance.

  
// Declare local identifiers:
HRESULT                        hr = S_OK;
CComPtr<ISpObjectWithToken>    cpObjectWithToken;
CComPtr<ISpObjectToken>        cpObjectToken;

hr = SpGetDefaultTokenFromCategoryId(SPCAT_VOICES, &cpObjectToken;);

if (SUCCEEDED (hr))
{
   hr = cpObjectToken->CreateInstance(NULL, CLSCTX_INPROC_SERVER, IID_ISpObjectWithToken, (void **)&cpObjectWithToken;);
}

if (SUCCEEDED(hr))
{
   // Do stuff here.
}