Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
04-28 07:08
관리 메뉴

zyint's blog

::CreateInstance 본문

예전글들

::CreateInstance

진트­ 2009. 3. 13. 08:28

ISpObjectToken::CreateInstance

creates an instance of an object.

 

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

파라미터

  • 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.

 

반환 값

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

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::SetVoice methods.

 

예제

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.
}

참고자료

http://msdn.microsoft.com/en-us/library/ms718229(VS.85).aspx

이 글은 스프링노트에서 작성되었습니다.

Comments