CComDispatchDriver InvokeN以result.lVal = -858993460返回Result [英] CComDispatchDriver InvokeN Returns Result with result.lVal = -858993460

查看:129
本文介绍了CComDispatchDriver InvokeN以result.lVal = -858993460返回Result的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试为Atl BHO(c ++)中的JavaScript Window.postMessage添加Window.PostMessage侦听器。



代码添加事件处理程序..
$


DISPID dispidAddEventListener = -1;

    if(FAILED(dispWindow.GetIDOfName(CComBSTR(" addEventListener"))& dispidAddEventListener))))
    {

    //失败..

   返回;

}

CListener * eventHandler;
$
if(FAILED(CListener :: Create(this,& eventHandler))) />
{

    //无法创建事件接收器

   返回;

}

IDispatch * eventHandlerAsDispatch;

if(FAILED(eventHandler-> QueryInterface(IID_IDispatch,reinterpret_cast< void **> (& eventHandlerAsDispatch)))))
{

  &NBSP; //无法获取事件接收器的IDispatch指针

  &NBSP;返回;

}

CComVariant结果;

CComVariant invokeParams [3];

invokeParams [0] = CComVariant (false);
$
invokeParams [1] = CComVariant(eventHandlerAsDispatch);

invokeParams [2] = CComVariant(L" message");

if(FAILED(dispWindow.InvokeN(dispidAddEventListener,invokeParams,3,& result))))
{

  &NBSP; //无法调用addEventListener方法

  &NBSP;返回;

}

if(FAILED(result.lVal))//在这里失败...

{

  &NBSP;返回;
$
}

但执行dispWindow.InvokeN后,result.lVal始终为-858993460,addEventListener失败。



任何想法上面的代码有什么问题。



Ashish Shivhare


I am trying to add Window.PostMessage listener for JavaScript Window.postMessage inside Atl BHO (c++).

Code for adding event handler..

DISPID dispidAddEventListener = -1;
    if (FAILED(dispWindow.GetIDOfName(CComBSTR("addEventListener"), &dispidAddEventListener)))
    {
    //failed..
    return;
}
CListener* eventHandler;
if (FAILED(CListener::Create(this, &eventHandler)))
{
    // Could not create the event sink
    return;
}
IDispatch* eventHandlerAsDispatch;
if (FAILED(eventHandler->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(&eventHandlerAsDispatch))))
{
    //Could not get an IDispatch pointer for the event sink
    return;
}
CComVariant result;
CComVariant invokeParams[3];
invokeParams[0] = CComVariant(false);
invokeParams[1] = CComVariant(eventHandlerAsDispatch);
invokeParams[2] = CComVariant(L"message");
if (FAILED(dispWindow.InvokeN(dispidAddEventListener, invokeParams, 3, &result)))
{
    //Could not invoke the addEventListener method
    return;
}
if (FAILED(result.lVal)) //failing here...
{
    return;
}
But after executing dispWindow.InvokeN The result.lVal is always -858993460, and addEventListener fails.

Any ideas what is wrong with above code.


Ashish Shivhare

推荐答案

2017年4月6日下午2:44 ,Ashish Shivhare写道:

On 4/6/2017 2:44 PM, Ashish Shivhare wrote:


if(FAILED(dispWindow.InvokeN(dispidAddEventListener,invokeParams,3,& result))))
{

  &NBSP; //无法调用addEventListener方法

  &NBSP;返回;

}

if(FAILED(lVal))//在这里失败...

if (FAILED(dispWindow.InvokeN(dispidAddEventListener, invokeParams, 3, &result)))
{
    //Could not invoke the addEventListener method
    return;
}
if (FAILED(lVal)) //failing here...

addEventListener不返回任何值。结果很可能是VT_EMPTY类型。成功或失败通过invokeN调用的返回值指示,您已经检查过。

addEventListener doesn't return any value. result is most likely of type VT_EMPTY. The success or failure is indicated via the return value of invokeN call, which you already check.


这篇关于CComDispatchDriver InvokeN以result.lVal = -858993460返回Result的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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