为什么IE不听ActiveX事件?

时间:2011-07-11 09:07:32

标签: c++ internet-explorer atl connection-points

我使用longrun方法将ActiveX控件放到HTML页面上,该方法应该触发IE要处理的事件。

它们不会因为m_vec.GetSize() == 0而触发,这意味着IE无法连接到我的ActiveX。

站点是localhost,它位于受信任的站点,安全级别设置为最小。

HTML

 <object id="myObj" name="myObj" ...>                    
 </object>   

   <script type="text/javascript" for="myObj" event="CallbackMethod(...)" language="javascript">
        alert("hello!");
    </script>

IDL

[uuid(...), dual]
interface _IBasicEvents : IDispatch
{   
    [id(1)] HRESULT CallbackMethod(...);
};

[uuid(...)] 
coclass MyService
{       
    [default] interface IBasicInterface;        
    [default, source] dispinterface _IBasicEvents;
};

С++继承列表:

class ATL_NO_VTABLE CMyService :
    public CComObjectRootEx<CComSingleThreadModel>, 
    public CComControl<CMyService>, 
    public CComCoClass<CMyService, &CLSID_MyService>,
    public IConnectionPointContainerImpl<CMyService>,       
    public IObjectWithSiteImpl<CMyService>,     
    public IPersistPropertyBagImpl<CMyService>, 
    public IObjectSafetyImpl<CMyService, INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA>,
    public IOleInPlaceObjectWindowlessImpl<CMyService>,
    public IOleObjectImpl<CMyService>,
    public IDispatchImpl<IBasicInterface, ...>,
    public CProxy_IScannerServiceEvents<CMyService>

COM_MAP

COM_INTERFACE_ENTRY(IBasicInterface)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
COM_INTERFACE_ENTRY(IObjectWithSite)    
COM_INTERFACE_ENTRY(IOleObject) 
COM_INTERFACE_ENTRY(IObjectSafety)  
COM_INTERFACE_ENTRY(IPersistPropertyBag)    

CONNECTION_POINT_MAP

CONNECTION_POINT_ENTRY(__uuidof(_IBasicEvents))

CATEGORY_MAP

IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)

这里有什么问题?为什么IE无法连接到我的连接点接口?

临时解决方案

我放弃了使用<script for event>的游戏并开始将javascript回调函数作为方法参数传递(类型IDispatch*

1 个答案:

答案 0 :(得分:0)

  

[uuid(...),dual] 界面 _IBasicEvents:IDispatch

     

[default,source] dispinterface _IBasicEvents;

AFAIK IDL coclass应该引用事件接口,如上所述,但_IBasicEvents未定义为dispainterface。相反,它是一个真实的界面,这是不正确的。应该有:

  

[...] dispinterface _IBasicEvents {methods:...};