我试图将COM对象从ActiveX组件传递到JScript。到目前为止,我已经尝试了以下方法:

STDMETHODIMP CHSNetwork::CreateIPPPacket(VARIANT ** ppv)
{
    IIPPacket *iipp;
    HRESULT hr = CoCreateInstance(CLSID_IPPacket, NULL, CLSCTX_ALL, IID_IIPPacket, (void **)&iipp);
    if(SUCCEEDED(hr) && ppv)
    {
        CComVariant cvar((IUnknown *)iipp);
        hr = cvar.Detach(*ppv);
    }

    return hr;
}

以下JScript导致错误Variable uses an Automation type not supported in JScript:
var hsn = new ActiveXObject("ZIENetwork.HSNetwork");
var ipp = hsn.CreateIPPPacket();

任何帮助将不胜感激。谢谢。

最佳答案

啊。我知道了。我需要传递一个VARIANT *而不是VARIANT **。我想我仍然对指针指向指针感到困惑,因为它与COM的返回值有关。

因此正确的代码是:

STDMETHODIMP CHSNetwork::CreateIPPPacket(VARIANT * ppv)
{
    // TODO: Add your implementation code here
    IIPPacket *iipp;
    HRESULT hr = CoCreateInstance(CLSID_IPPacket, NULL, CLSCTX_ALL, IID_IIPPacket, (void **)&iipp);
    if(ppv)
    {
        CComVariant cvar((IUnknown *)iipp);
        hr = cvar.Detach(ppv);
    }

    return hr;
}

关于c++ - 将COM对象返回到JScript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3313777/

10-10 15:21