ISpRecoResult::Serialize (Windows CE 5.0)

Send Feedback

This method creates a serialized copy of the recognition result object. The serialized copy can be saved and later restored using the ISpRecoContext::DeserializeResult method.

HRESULT Serialize(SPSERIALIZEDRESULT** ppCoMemSerializedResult);

Parameters

  • ppCoMemSerializedResult
    [out] Address of a pointer to an SPSERIALIZEDRESULT structure containing the serialized result information. The application should call CoTaskMemFree to free the memory associated with the serialized result.

Return Values

The following table shows the possible return values.

Value Description
S_OK Function completed successfully.
E_POINTER ppCoMemSerializedResult is an invalid pointer.
E_OUTOFMEMORY Exceeded available memory.
FAILED(hr) Appropriate error message.

Example

The following code snippet illustrates the use this method to serialize a result and deserialize it back into an ISpRecoContext object.

HRESULT hr = S_OK;
// ... obtain a recognition result object from the recognizer...
SPSERIALIZEDRESULT* pSerializedResult = NULL;
ULONG cbWritten = 0;
ULONG ulSerializedSize = 0;
LARGE_INTEGER liseek;
LARGE_INTEGER li;
CComPtr<IStream> cpStreamWithResult;
hr = CreateStreamOnHGlobal(NULL, true, &cpStreamWithResult);
// Check hr
// Serialize result to memory
hr = cpRecoResult->Serialize(&pSerializedResult);
// Check hr
//serialized to a stream pointer
hr = cpStreamWithResult->Write(pSerializedResult,
             pSerializedResult->ulSerializedSize, 
                                      &cbWritten);
// Check hr
// free the serialized result
if (pSerializedResult) ::CoTaskMemFree(pSerializedResult);
// commit the stream changes
hr = cpStreamWithResult->Commit(STGC_DEFAULT);
// Check hr
// ... persist stream to disk, network share, and so on...
// ... shutdown application .... 
// ... restart application and get the persisted stream
// reset the stream seek pointer to the start before deserialization
li.QuadPart = 0;
hr = cpStreamWithResult->Seek(li, STREAM_SEEK_SET, NULL);
// Check hr
// find the size of the stream
hr = cpStreamWithResult->Read(&ulSerializedSize, sizeof(ULONG), NULL);
// Check hr
// reset the seek pointer
liseek.QuadPart = 0 - sizeof(ULONG);
hr = cpStreamWithResult->Seek(liseek, STREAM_SEEK_CUR, NULL);
// Check hr
// allocate the memory for the result
pSerializedResult = (SPSERIALIZEDRESULT*)::CoTaskMemAlloc(ulSerializedSize);
// Check pSerializedResult in case "out of memory"
// copy the stream into a serialized result object
hr = cpStreamWithResult->Read(pSerializedResult, ulSerializedSize, NULL);
// Check hr
// Deserialize result from memory
hr = cpRecoContext->DeserializeResult(pSerializedResult, &cpRecoResultNew);
// Check hr
// free the pSerializedResult memory
if (pSerializedResult) {
  CoTaskMemFree(pSerializedResult);
}
// As long as the same engine was used to generate
// the original result object, as is now being used,
// applications can now get alternates for the cpRecoResultNew's phrase

Requirements

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

See Also

ISpRecoResult | SAPI Interfaces

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.