不知道如何正确使用IShellWindows :: Item [英] don't know how to use IShellWindows::Item correctly
问题描述
我在XP系统上使用VC6。
I'm using VC6 on XP system.
以下是我的代码。它在我的计算机上运行完美,但在其他计算机上,似乎pisw-> Item(v,&pidisp)不等于S_OK。现在我想弄清楚这里有什么错误
The following is my code. It runs perfectly on my computer, but on other computers it seems that pisw->Item(v, &pidisp) doesn't equals to S_OK. Now I'm trying to figure out what's wrong here
IShellWindows *pisw;
if (SUCCEEDED(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL,
IID_IShellWindows, (void**)&pisw))) {
VARIANT v;
V_VT(&v) = VT_I4;
IDispatch *pidisp;
found = FALSE;
for (V_I4(&v) = 0; !found && pisw->Item(v, &pidisp) == S_OK; V_I4(&v)++) {
IWebBrowserApp *piwba;
if (SUCCEEDED(pidisp->QueryInterface(IID_IWebBrowserApp, (void**)&piwba))) {
// blablabla....do something..
}
所以我改变了一些代码到
So I changed some code to
...
IDispatch *pidisp;
hr = pisw->Item(v, &pidisp);
if (SUCCEEDED(hr))
{
for (V_I4(&v) = 0; !found ; V_I4(&v)++) {
IWebBrowserApp *piwba;
if (SUCCEEDED(pidisp->QueryInterface(IID_IWebBrowserApp, (void**)&piwba))) {
// blablabla....do something..
}
}
到1.当运行到pidisp-> ..步骤时,它获取访问冲突错误。
then the return value of hr becomes to 1. And it gets access violation errors when running to "pidisp->.." step. Can anyone help me?
推荐答案
原始代码错误地测试了 pisw-> Item v,& pidisp)
。
The original code incorrectly tests the result of pisw->Item(v, &pidisp)
. Weird, because it does use the correct check later on.
问题是,除了 S_OK $ c $,还有许多成功的返回值c>。您的修正是正确的,您应该使用
SUCCEEDED(hr)
,但您错误地将循环移到 SUCCEEDED(hr)
测试。对于 V_I4(& v)
的每个值,应检查 SUCCEEDED(hr)
。
The problem is that there are many success return values besides S_OK
. Your fix is correct, you should use SUCCEEDED(hr)
, but you incorrectly moved the loop INSIDE the SUCCEEDED(hr)
test. You should check SUCCEEDED(hr)
for every value of V_I4(&v)
.
您的 S_FALSE
结果是因为您现在呼叫 hr = pisw-> Item v,& pidisp);
之前的循环,这意味着 v
是未初始化的(垃圾)。假设它的垃圾值为728365. S_FALSE
意味着:调用成功,但有不到728365窗口。
Your S_FALSE
result is because you now call hr = pisw->Item(v, &pidisp);
before the loop, which means v
is uninitialized (garbage). Assume for a moment that its garbage value is 728365. S_FALSE
means: the call succeeded, but there are less than 728365 windows.
这篇关于不知道如何正确使用IShellWindows :: Item的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!