EXE は IScriptControlPtr で jscript を呼び出します。
obj.dec = myobject_dec
しかし、jscript は COM イベントをアタッチできず、「オブジェクトはこのプロパティまたはメソッドをサポートしていません」というメッセージをスローします
次の jscript のコード:
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
}
次のコムコード:
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;
};
};
次の実装コード
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()
次のexeコード:
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 );
jscriptでIScript::decイベントをアタッチする方法???