ISpPhraseBuilder::InitFromSerializedPhrase
ISpPhraseBuilder::InitFromSerializedPhrase initializes a phrase from a serialized phrase.
HRESULT InitFromSerializedPhrase(
const SPSERIALIZEDPHRASE *pPhrase
);
Parameters
- pPhrase
- Address of the SPSERIALIZEDPHRASE structure that contains the phrase information.
Return values
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_INVALIDARG | pSrcPhrase or pSrcPhrase->cbSerializedSize is invalid or bad. |
FAILED(hr) | Appropriate error message. |
Remarks
Before passing a serialized phrase into this function, first make certain that the size of the buffer being passed is equal to pPhrase->ulSerializedSize.
Example
The following code fragment demonstrates the use of InitFromSerializedPhrase.
// Declare local identifiers:
HRESULT hr = S_OK;
CComPtr<ISpRecoResult> RecoResult;
CComPtr<ISpPhraseBuilder> cpPhraseBuilder;
CComPtr<ISpStream> cpStream;
SPSERIALIZEDPHRASE *pSerializedPhrase=NULL;
LARGE_INTEGER liZero = {0,0};
ULONG ulSerializedSize = 0;
LARGE_INTEGER liseek;
// Bind audio stream to specified file (note
// that SerializedPhrase.sp is a dummy file).
hr = SPBindToFile(L"SerializedPhrase.sp", SPFM_OPEN_READONLY, &cpStream;, NULL, NULL, SPFEI_ALL_EVENTS);
if (SUCCEEDED(hr))
{
hr = cpStream->Seek(liZero, STREAM_SEEK_SET, NULL);
}
if (SUCCEEDED(hr))
{
hr = cpStream->Read(&ulSerializedSize;, sizeof(ULONG), NULL);
}
if (SUCCEEDED(hr))
{
// Need to seek back and read the whole chunk of data in:
liseek.QuadPart -= sizeof(ULONG);
hr = cpStream->Seek(liseek, STREAM_SEEK_CUR, NULL);
}
if (SUCCEEDED(hr))
{
pSerializedPhrase = (SPSERIALIZEDPHRASE*)::CoTaskMemAlloc(ulSerializedSize);
}
if (SUCCEEDED(hr) && pSerializedPhrase)
{
hr = cpStream->Read(pSerializedPhrase, ulSerializedSize, NULL);
}
if (SUCCEEDED(hr) && pSerializedPhrase)
{
hr = cpPhraseBuilder.CoCreateInstance(CLSID_SpPhraseBuilder);
}
if (SUCCEEDED(hr))
{
hr = cpPhraseBuilder->InitFromSerializedPhrase(pSerializedPhrase);
}
if (SUCCEEDED(hr))
{
::CoTaskMemFree(pSerializedPhrase);
}