在vc ++中启动线程的示例演示 [英] sample demo of starting a thread in vc++

查看:110
本文介绍了在vc ++中启动线程的示例演示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在按钮上单击并启动一个线程,并在线程中调用一个方法,并在MFC的main函数中使用方法的返回值。



char * exampleDlg :: methodname(char * protType)

{

-------

-------

------

-------

返回;

}

i am trying to start a thread on button click and call a method in thread and use the return value of method in the main function in MFC.

char* exampleDlg::methodname(char *protType)
{
-------
-------
------
-------
return;
}

void exampleDlg::Onclick()
{

THREADSTRUCT *_param = new THREADSTRUCT;
    _param->_this = this;
    AfxBeginThread (StartThread, _param);




}


UINT exampleDlg::StartThread(LPVOID param)
{
methodname();
return k;
_endthread();
}

推荐答案

您无法将实例方法传递给 AfxBeginThread 。此处显示了一种解决方法:回调,线程和MFC [ ^ ](参见页面底部的类中的工作线程部分。)
You cannot pass instance methods to AfxBeginThread. A workaround is shown here: "Callbacks, Threads, and MFC"[^] (see the the "Worker Threads in a class" section at the bottom of the page).


这篇关于在vc ++中启动线程的示例演示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆