UIAutomation 调用返回的最大数据长度 [英] Max length of data returned from UIAutomation call

查看:27
本文介绍了UIAutomation 调用返回的最大数据长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Windows 7 C++ 程序,它将捕获屏幕上的文本.微软的 UIAutomation 框架似乎是实现它的最佳方式.我已经得到了很多工作,除了一件事——当我使用框架的函数来获取文本时,它似乎只返回前一百万个字符.这可能看起来很多,但是尝试列出硬盘驱动器上的每个文件,它很快就会达到数百万个字符的范围.我尝试了两种不同的方法来获取该文本,两种方法都返回相同的内容,并且都限于前一百万个字符.

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.

以下是代码示例:

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.

我假设可能有两个地方出现问题.首先,VARIANT 可能只能容纳一百万个字符,但根据我对 Microsoft 的 VARIANT 实施的了解,这似乎不正确.第二个是 GetCurrentPropertyValue() 调用最多只能返回一百万个字符.这很糟糕,因为我没有找到解决方法.

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.

请注意,我也使用 IUIAutomationValuePattern 和 IUIAutomationTextRange 完成了此操作,但它产生了相同的结果.

Note that I've also done this using IUIAutomationValuePattern and IUIAutomationTextRange, but it yields the same results.

有什么想法吗?

推荐答案

在对代码进行更多检测后,我意识到我关于 VARIANT 能够容纳超过一百万个字符的能力的断言是错误的.实际发生的是我从 VARIANT 中提取的 BSTR 保存了所有数据,因此它根本没有截断.真正发生的是我从 BSTR 创建的 wstring(为了便于字符串操作)进行截断.好像

After instrumenting the code a bit more, I've realized that I'm incorrect in my assertion about VARIANT's ability to hold more than a million characters. What's actually happening is that the BSTR I'm pulling from the VARIANT is holding all the data, so it's not truncating at all. What's really happening is that the wstring that I'm creating from the BSTR (for ease of string manipulation) is what's doing the truncating. Seems as if

wstring(tempString);

只会给我一个最多一百万个字符的字符串.所以,虽然我还没有解决这个问题,但我已经成功地进一步缩小了罪魁祸首的范围,至少这是一个易于处理的问题,因为我实际上并没有丢失数据.

will only give me a string of at most a million characters. So, while I haven't fixed the problem, I have succeeded in narrowing down the culprit some more, and at least it's a tractable problem, since I'm not actually losing the data.

我对 wstring 处理超长字符串的能力也是错误的.如果我只查看 wstring 的长度,我会发现它正确地复制了 BSTR.这是一种解脱.

And I'm wrong about wstring's ability to handle ultra-long strings too. If I just look at the length of the wstring, I see that it's copying the BSTR correctly. Which is a relief.

限制为一百万个字符的是 Visual Studio 2015 的字符串检查工具——无论何时我查看 wstring 的内容,它都不会超过一百万个字符.

The thing that is limited to one million characters is Visual Studio 2015's string inspection facility--anytime I'd look at the contents of the wstring, it would be no longer than one million characters.

所以,感谢您帮助我完成的这段自我发现之旅——这里没有什么可看的了.向前走.继续前进.

So, thanks for this journey of self-discovery you've helped me with--nothing more to see here. Move along. Move along.

这篇关于UIAutomation 调用返回的最大数据长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆