class ClientListener : public IClientListener
{
public:
ClientListener(IClientListenerEx ^ pListener)
{
//pListener为C#对象,我怎么用变量保存它
}
private:
IClientListenerEx ^ m_pListener;//在C++中直接定义此变量有错
}
关于在C++DLL中使用C#对象的问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
染指一梦 2017-06-28 10:38关注class ClientListener : public IClientListener
{
public:
ClientListener(IClientListenerEx ^ pListener)
{
gcrootpTmp = new gcroot(pListener);
m_pListener = static_cast<void>(pTmp);
}
~ClientListener()
{
if (m_pListener)
{
gcrootpTmp = static_cast>(m_pListener);
delete pTmp;
m_pListener = NULL;
}
}
void Call(int code)
{
gcrootpTmp = static_cast>(m_pListener);
((IClientListenerEx ^)*pTmp)->OnStatusChanged(code);
}
private:
void* m_pListener;
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报