1

EXE call jscript by IScriptControlPtr,like it

obj.dec = myobject_dec

but jscript can't attach COM Event, throw "Object doesn't support this property or method" message

The following jscript's code:

var obj1;

function myobject_dec()
{
    obj1.messagebox("xxx");
}

function myobject_main(obj)
{
    obj1 = obj;
    obj.dec=myobject_dec; //it's report "Object doesn't support this property or method"
    obj.test("bbb");//it's fire dec event
}

The following com code:

 interface IScript : IDispatch {
        [id(1)] HRESULT test([in] BSTR aaa);
        [id(3)] HRESULT get_script([out,retval] IDispatch** jscript);
    };
    [
        uuid(702C44D6-6649-4FA7-8B19-2E59DB7116EF),
        version(1.0),
        helpstring("testScript 1.0")
    ]
    library testScriptLib
    {
        importlib("stdole2.tlb");
        [
            uuid(2BF42BF6-457E-4923-9DFF-59BAD961EE6C),
            helpstring("_IScriptEvents ")
        ]
        dispinterface _IScriptEvents
        {
            properties:
            methods:
                [id(1)] HRESULT add([in] BSTR a, BSTR b);
                [id(2)] HRESULT dec(void);
        };
        [
            uuid(6ED96EBA-4144-47FA-9467-7C41A6BFA155),
            helpstring("Script Class")
        ]
        coclass Script
        {
            [default] interface IScript;
            [default, source] dispinterface _IScriptEvents;
        };
    };

the following implement code

class ATL_NO_VTABLE CScript :
    public CComObjectRootEx<CComMultiThreadModel>,
    public CComCoClass<CScript, &CLSID_Script>,
    public IProvideClassInfo2Impl<&CLSID_Script, NULL, &LIBID_testScriptLib>,
    public IConnectionPointContainerImpl<CScript>,
    public CProxy_IScriptEvents<CScript>,
    public IDispatchImpl<IScript, &IID_IScript, &LIBID_testScriptLib, /*wMajor =*/ 1, /*wMinor =*/ 0>


BEGIN_COM_MAP(CScript)
    COM_INTERFACE_ENTRY(IProvideClassInfo2)
    COM_INTERFACE_ENTRY(IProvideClassInfo)
    COM_INTERFACE_ENTRY(IScript)
    COM_INTERFACE_ENTRY(IDispatch)
    //COM_INTERFACE_ENTRY(IDispatchEx) 
    COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CScript)
    CONNECTION_POINT_ENTRY(__uuidof(_IScriptEvents))
END_CONNECTION_POINT_MAP()

the following exe code:

CComSafeArray<VARIANT> sfHelper;
IDispatchPtr dispatch(script_);//IScriptPtr script_
sfHelper.Add(CComVariant(dispatch.GetInterfacePtr()));
LPSAFEARRAY* sa =  sfHelper.GetSafeArrayPtr();
_variant_t varRet;
varRet = m_pScript->Run(_T("myobject_main"), sa );

How to attach IScript::dec event at jscript???

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.