1、VS2010 release模式运行,javaScript第一次调用C++成功,第二次就弹窗报错了
2、点击继续后
3、javacript调用的代码:
void CHtmlCtrl::getGsName(LPCTSTR gsName )
{
CString str=CString(gsName);
CString *gname=new CString(str);
if(GetParent())
{
GetParent()->PostMessage(WM_GSNAME_NAVI,(WPARAM)gname,NULL);
}
}
4、接收post消息后执行的代码:
LRESULT CDlgYLTXGameWnd::OnSetGsName( WPARAM wParam,LPARAM lParam )
{
CString* gsName = (CString*)wParam;
m_btnUser.ShowWindow(SW_SHOW);
m_btnUser.SetTitle(*gsName);
if(gsName)
delete gsName;
return 0;
}
5、实现javascript调用C++方式:
头文件:
DECLARE_DISPATCH_MAP();
void setGsURL(LPCTSTR gsurl);
void getGsName(LPCTSTR gsName);
void getNewMsg(LPCTSTR gsMsg);
CPP实现
a、BEGIN_DISPATCH_MAP(CHtmlCtrl, CHtmlView)
DISP_FUNCTION(CHtmlCtrl, "setGsURL", setGsURL, VT_BSTR, VTS_BSTR)
DISP_FUNCTION(CHtmlCtrl, "getGsName", getGsName, VT_BSTR, VTS_BSTR)
DISP_FUNCTION(CHtmlCtrl, "getNewMsg", getNewMsg, VT_BSTR, VTS_BSTR)
END_DISPATCH_MAP()
b、EnableAutomation();
c、HRESULT CHtmlCtrl::OnGetExternal(LPDISPATCH *lpDispatch)
{
*lpDispatch=GetIDispatch(TRUE);
return S_OK;
}
小弟菜鸟,大神帮忙看看哪里的问题,不胜感激!!!