0

我想从一个指针中获取 wstring,该指针指向一个给出了偏移量和长度的文本。

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.

我尝试了以下方法:

    wstring sText;
    sText = nFragList->pTextStart;
    sText = sText.substr(nFragList->ulTextSrcOffset,nFragList->ulTextLen);

但这完全奇怪,生成的 wstring 在错误的位置被切断并且太短。

对 LPCWSTR 有更深入了解的人可以告诉我如何正确地做到这一点吗?

非常感谢!

4

1 回答 1

0

问题其实是你对SPVTEXTFRAG. 这是一个碎片,所以预计会被砍掉。您必须重新组装所有碎片。最后一个片段可以被识别pNext==nullptr

此外,您不应该调用substr片段。它已经是一个片段,你不需要片段的片段。

于 2013-12-05T15:36:52.377 回答