I want to get the wstring from a pointer to a text for which an offset and a length is given.
typedef struct SPVTEXTFRAG
{
struct SPVTEXTFRAG *pNext;
SPVSTATE State;
LPCWSTR pTextStart;
ULONG ulTextLen;
ULONG ulTextSrcOffset;
} SPVTEXTFRAG;
pTextStart is a pointer to the beginning of the text associated with the fragment.
ulTextLen is the length of this text, in WCHARs.
ulTextSrcOffset is the offset of the first character of the text associated with the fragment.
Finally, State is the SAPI 5.0 XML state associated with this fragment.
See the XML TTS Tutorial for more details.
I tried the following:
wstring sText;
sText = nFragList->pTextStart;
sText = sText.substr(nFragList->ulTextSrcOffset,nFragList->ulTextLen);
But that it totally strange, the resulting wstring is chopped off at the wrong place and too short.
Could somebody with a deeper understanding of LPCWSTR perhaps tell me how to do it correctly?
Thank you very much!
The problem is in fact your understanding of
SPVTEXTFRAG
. It's a single fragment, so it's expected to be chopped off. You must reassemble all fragments. The last fragment can be recognized bypNext==nullptr
.Aslo, you should not call
substr
on a fragment. It already is a fragment, you don't need fragments of fragments.