void MyExit() //PostMessage(CUIThread::s_hWnd,WM_QUIT,0,0);

本文展示了一个MATLAB MEX函数中的清理与退出流程示例。该示例通过循环等待主线程结束并发送退出消息,确保资源得到适当释放。此外,还演示了如何注册一个退出函数以在MEX函数被清除时执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void MyExit()
{
while(CUIThread::s_hWnd!=NULL)
{
   long res=PostMessage(CUIThread::s_hWnd,WM_QUIT,0,0);	
   //char buff[255];
   //wsprintf(buff,"%d",res);
   //MessageBox(NULL,buff,"MyExit()",MB_OK);
   Sleep(1000);
   //CUIThread::s_hWnd=NULL;
}
mexPrintf("Matlab Addon Exit!\n");
/* Do cleanup here ... */
return;
}
extern void MyBeep(int times);
bool noUIThread=true;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

//MyBeep(1);
mexAtExit(&MyExit); /* Register MyExit() to run when MEX??function is cleared */
//mexPrintf("Count=%d\n", Count);
//Count++; /* Increment Count */
// CUIThread* pThread=new CUIThread();
// pThread->CreateThread();
if(noUIThread)
 CWinThread *pThread=AfxBeginThread(RUNTIME_CLASS(CUIThread));
return;
}

/media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so(_Z29simGetInt32Parameter_internaliPi+0x2da)[0x7f08796d868a] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_ZN16CPluginContainer9addPluginEPKcS1_+0x3df)[0x7f19a16c4eaf] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libsimExtCustomUI.so(_Z21simGetInt32ParameterEi+0x29)[0x7f086e281f19] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_Z11_segHandleri+0x30)[0x7f1e62d81ae0] /lib/x86_64-linux-gnu/libc.so.6(+0x43090)[0x7f1eb7868090] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libsimExtCustomUI.so(simStart+0xdc)[0x7f086e25b6ac] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_ZN9CUiThread27__executeCommandViaUiThreadEP16SUIThreadCommandS1_+0x247a)[0x7f19a165479a] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so(_Z29simGetInt32Parameter_internaliPi+0x2da)[0x7f1c7098668a] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_ZN7CPlugin4loadEv+0xa7)[0x7f0a6d491e17] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libsimExtCustomUI.so(_Z21simGetInt32ParameterEi+0x29)[0x7f1c6149ef19] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_ZN9CUiThread25executeCommandViaUiThreadEP16SUIThreadCommandS1_+0x3d)[0x7f19a165519d] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libsimExtCustomUI.so(simStart+0xdc)[0x7f1c614786ac] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_ZN16CPluginContainer9addPluginEPKcS1_+0x3df)[0x7f0a6d499eaf] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_Z22simLoadModule_internalPKcS0_+0x3fc)[0x7f19a14f872c] /media/dell/XNW/coppeliasim/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04/libcoppeliaSim.so.1(_ZN7CPlugin4loadEv+0xa7)[0x7f1e62f49e17] /media/dell/XNW/coppeli
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值