views:

35

answers:

2

Hi. I am trying to pass a COM object from an ActiveX component to JScript. So far I have tried the following method of doing so:

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;
}

The following JScript causes the error Variable uses an Automation type not supported in JScript:

var hsn = new ActiveXObject("ZIENetwork.HSNetwork");
var ipp = hsn.CreateIPPPacket();

Any help would be greatly appreciated. Thanks.

+1  A: 

Ah. I got it. I needed to pass a VARIANT * not a VARIANT **. I guess I still get confused by pointers-to-pointers as it relates to return values with COM.

Thus the correct code is:

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;
}
Arun Seehra
A: 

Of course if you only ever pass back an interface you can pass back a IDispatch** or IUnknown**, you don't need the VARIANT, just a thought :)

tyranid