I'm working on a Windows 7 C++ program that will capture the text on a screen. Microsoft's UIAutomation framework seems to be the best way of going about it. I've got it pretty much working, except for one thing--when I use the framework's functions to get the text, it seems to only be returning the first million characters. That might seem like a lot, but try doing a listing of every file on your hard drive, and it very quickly gets up in the multi-million-character range. I've tried two different ways to get that text, and both ways return the same thing, and both are limited to the first million characters.
Here's a sample of the code:
IUIAutomationElement *element = findElement();
VARIANT v;
VariantInit(&v);
element->GetCurrentPropertyValue(UIA_LegacyIAccessibleValuePropertyId, &v);
BSTR tempString = V_BSTR(&v);
Everything works as intended when the amount of text is less than a million characters long, but anything over that limit gets truncated.
I hypothesis that there might be two places where the problem occurs. First, it's possible that a VARIANT can only hold a million characters, but that seems to not be correct, based on what I could find out about Microsoft's VARIANT implemented. The second is that the GetCurrentPropertyValue() call only returns up to a million characters. Which is rather bad because I don't see a way around it.
Note that I've also done this using IUIAutomationValuePattern and IUIAutomationTextRange, but it yields the same results.
Any thoughts?