ISpObjectToken::CreateInstance (Windows CE 5.0)

Send Feedback

This method creates an object token by creating the underlying object that the object token represents. The method looks at the class identifier stored in the object token and creates a COM object from this identifier. 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 retrieved.

This method is not used to create speech recognition or TTS 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::SetVoice method.

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

Parameters

  • pUnkOuter
    [in] Pointer to the controlling IUnknown interface of the aggregate, if the object is being created as part of an 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 a pointer to the interface indicated by riid. On successful return from this method, 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

The following table shows the possible return values.

Value Description
S_OK Function completed successfully.
E_POINTER ppvObject is invalid or bad.
E_INVALIDARG pUnkOuter is invalid or bad.
SPERR_UNINITIALIZED Either the data key or the token delegator interface is not initialized.
SPERR_TOKEN_DELETED Key has been deleted.
FAILED(hr) Appropriate error message.

Remarks

The following code snippet creates an InProc server instance.

HRESULT hr;

CComPtr cpSpObjectToken;
CComPtr cpSpObjectWithToken;

hr = SpGetDefaultTokenFromCategoryId(SPCAT_VOICES, &cpSpObjectToken);
//Check return value

hr = cpSpObjectToken->CreateInstance(
NULL, CLSCTX_INPROC_SERVER, IID_ISpObjectWithToken,
(void **)&cpSpObjectWithToken
); 
//Check return value

Requirements

OS Versions: Windows CE .NET 4.1 and later.
Header: sapi.h, sapi.idl.
Link Library: Sapilib.lib.

See Also

ISpObjectToken | SAPI Interfaces

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.