سؤال

I am trying to use MSHTML in my C# application (BHO). In particular I want to use IMarkupPointer.findText method. This method searches for text and I want to check if text was found or not. When doing this in C++, I just did like this:

HRESULT hr = ptrBegin->FindText(text, 0, ptrEnd, NULL); 
if (S_FALSE == hr) 
{
    // Do something if text wasn't found.
}

but in C# I can't do that because in PIA this method has void return type. Is there other way to check if text was found or not?

هل كانت مفيدة؟

المحلول

In this particular case I have used following workaround to find out if text was found or not:

IMarkupPointer pBegin, pEnd;
IMarkupServices markupServices;
// ...

pBegin.findText(word, 2, pEnd, null);

IHTMLTxtRange range = htmlDocument2.selection.createRange();
markupServices.MoveRangeToPointers(pBegin, pEnd, range);

if(range.text != word)
{
    // ...Text not found
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top