无法在MFC ActiveX中调用方法

时间:2014-07-23 02:52:40

标签: c++ visual-c++ visual-studio-2012 mfc activex

我在VS2012中使用一些接口方法创建了一个MFC ActiveX控件,这些方法运行良好。 当我今天向ActiveX添加一些新方法时,我可以在&#34; activex控制测试容器&#34;中看到新方法,但是我无法调用它们< / strong>(调用方法,什么也没发生)。当我试图用JS调用方法时,这也发生在IE11中。永远不会达到这些新方法的断点。 旧方法表现正常,我以相同的方式添加新方法。我不知道如何去理解,有人能帮帮我吗?非常感谢。 这是一种新方法的实现。

LONG CDCMonitorControllerClientCtrl::Init(LPCTSTR config)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    MessageBox(_T("Call Init"));
    return 0;
}

/ ************* **************************** /

我刚解决了这个问题。

调度图中的语句必须与头文件中的调度ID的顺序相同。

我在添加旧方法后添加了一些事件。当我添加一个新方法时,VS将dispatch语句添加到BEGIN_DISPATCH_MAP部分的末尾,该部分放在事件调度语句之后。我将新方法的dispatch语句移动到旧方法的最后一个dispatch语句的下一个,一切正常。 以下是调度和事件ID( Init StopListen 是新方法):

enum {
    dispidStopListen = 11L,
    dispidInit = 10L,
    dispidTsapiDisconnected = 20L,
    dispidInterceptEnded = 19L,
    dispidInsertEnded = 18L,
    dispidListenEnded = 17L,
    dispidForceReleaseFailed = 16L,
    dispidForceReleseSuccess = 15L,
    dispidInterceptFailed = 14L,
    dispidInterceptSuccess = 13L,
    dispidStopInsertFailed = 12L,
    dispidStopInsertSuccess = 11L,
    dispidInsertFailed = 10L,
    dispidInsertSuccess = 9L,
    dispidStopListenFailed = 8L,
    dispidStopListenSuccess = 7L,
    dispidListenFailed = 6L,
    dispidListenSuccess = 5L,
    dispidLogoutFailed = 4L,
    dispidLogoutSuccess = 3L,
    dispidLoginFailed = 2L,
    dispidLoginSuccess = 1L,
    dispidForceLogout = 9L,
    dispidForceBusy = 8L,
    dispidForceFree = 7L,
    dispidIntercept = 6L,
    dispidForceRelease = 5L,
    dispidInsert = 4L,
    dispidListen = 3L,
    dispidMonitorLogout = 2L,
    dispidMonitorLogon = 1L
};

这是新的 BEGIN_DISPATCH_MAP 部分:

BEGIN_DISPATCH_MAP(CDCMonitorControllerClientCtrl, COleControl)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "MonitorLogon", dispidMonitorLogon, MonitorLogon, VT_I4, VTS_BSTR VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "MonitorLogout", dispidMonitorLogout, MonitorLogout, VT_I4, VTS_BSTR VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "Listen", dispidListen, Listen, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "Insert", dispidInsert, Insert, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ForceRelease", dispidForceRelease, ForceRelease, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "Intercept", dispidIntercept, Intercept, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ForceFree", dispidForceFree, ForceFree, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ForceBusy", dispidForceBusy, ForceBusy, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ForceLogout", dispidForceLogout, ForceLogout, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "Init", dispidInit, Init, VT_I4, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "StopListen", dispidStopListen, StopListen, VT_I4, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "LoginSuccess", dispidLoginSuccess, LoginSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "LoginFailed", dispidLoginFailed, LoginFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "LogoutSuccess", dispidLogoutSuccess, LogoutSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "LogoutFailed", dispidLogoutFailed, LogoutFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ListenSuccess", dispidListenSuccess, ListenSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ListenFailed", dispidListenFailed, ListenFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "StopListenSuccess", dispidStopListenSuccess, StopListenSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "StopListenFailed", dispidStopListenFailed, StopListenFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "InsertSuccess", dispidInsertSuccess, InsertSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "InsertFailed", dispidInsertFailed, InsertFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "StopInsertSuccess", dispidStopInsertSuccess, StopInsertSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "StopInsertFailed", dispidStopInsertFailed, StopInsertFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "InterceptSuccess", dispidInterceptSuccess, InterceptSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "InterceptFailed", dispidInterceptFailed, InterceptFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ForceReleseSuccess", dispidForceReleseSuccess, ForceReleseSuccess, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ForceReleaseFailed", dispidForceReleaseFailed, ForceReleaseFailed, VT_EMPTY, VTS_BSTR)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "ListenEnded", dispidListenEnded, ListenEnded, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "InsertEnded", dispidInsertEnded, InsertEnded, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "InterceptEnded", dispidInterceptEnded, InterceptEnded, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CDCMonitorControllerClientCtrl, "TsapiDisconnected", dispidTsapiDisconnected, TsapiDisconnected, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()

我更改了 Init StopListen 的位置。

1 个答案:

答案 0 :(得分:0)

我刚解决了这个问题。

调度图中的语句必须与头文件中的调度ID的顺序相同。

我已经更新了细节问题,感谢@RogerRowland