4633|6

76

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

WIN CE 创建线程的时候编译错误 [复制链接]

编译错误:
ompiling...
ThreadDlg.cpp
D:\1\Thread\ThreadDlg.cpp(91) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__cdecl *)(void *)'
        None of the functions with this name in scope match the target type
D:\1\Thread\ThreadDlg.cpp(92) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__cdecl *)(void *)'
        None of the functions with this name in scope match the target type
Error executing clarm.exe.

ThreadDlg.obj - 2 error(s), 0 warning(s)

代码:
DWORD CThreadDlg::ThreadProc(PVOID pArg)
{
        int i;
        TCHAR tmp[10];
        CListBox *pListBox;
        pListBox=(CListBox*)pArg;
        i=0;
        while(1)
        {
                _itow(i,tmp,10);
                pListBox->AddString (tmp);        //显示当前线程的计数值
                i++;                                                //增加计数值
                Sleep(200);                                        //延时200Ms
        }
        return i;
}

void CThreadDlg::OnBtnexec()
{
        // TODO: Add your control notification handler code here
        DWORD dwThreadId1,dwThreadId2;
        HANDLE handle1,handle2;

        CListBox *pListOne;
        CListBox *pListTwo;
        pListOne=(CListBox*)GetDlgItem(IDC_LISTONE);
        pListTwo=(CListBox*)GetDlgItem(IDC_LISTTWO);

        //创建线程
        handle1=CreateThread(NULL,0,ThreadProc,pListOne,0,&dwThreadId1);
        handle2=CreateThread(NULL,0,ThreadProc,pListTwo,0,&dwThreadId2);

        if(!handle1)
        {
                AfxMessageBox(_T("Thread 1 create failed"));
        }
        if(!handle2)
        {
                AfxMessageBox(_T("Thread 2 Create failed"));
        }

        CloseHandle(handle1);
        CloseHandle(handle2);       
}

最新回复

也可以写成静态函数,用static,但需要对ThreadProc里面用到的类成员变量的引用做必要的修改,才能正确编程  详情 回复 发表于 2007-3-15 14:02
点赞 关注

回复
举报

75

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
使用全局函数作为线程的执行函数,而不是放在类里面。
比如
UINT ThreadProc(LPVOID para)
{
.....
}

void CThreadDlg::OnBtnexec()
{
        // TODO: Add your control notification handler code here
        DWORD dwThreadId1,dwThreadId2;
        HANDLE handle1,handle2;

        CListBox *pListOne;
        CListBox *pListTwo;
        pListOne=(CListBox*)GetDlgItem(IDC_LISTONE);
        pListTwo=(CListBox*)GetDlgItem(IDC_LISTTWO);

        //创建线程
        handle1=CreateThread(NULL,0,ThreadProc,pListOne,0,&dwThreadId1);
        handle2=CreateThread(NULL,0,ThreadProc,pListTwo,0,&dwThreadId2);

       
               
}
 
 

回复

61

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
强制类型转换
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

4
 
2楼你能说的清楚点吗?我是新手,不怎么懂啊
 
 
 

回复

70

帖子

0

TA的资源

一粒金砂(初级)

5
 
在线程函数的最前面加static
 
 
 

回复

63

帖子

0

TA的资源

一粒金砂(初级)

6
 
他说线程的执行函数ThreadProc方法,不要作为一个类的函数,应该是一个全局的。即UINT ThreadProc(LPVOID para)
而不是
DWORD CThreadDlg::ThreadProc(PVOID pArg)
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

7
 
也可以写成静态函数,用static,但需要对ThreadProc里面用到的类成员变量的引用做必要的修改,才能正确编程
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表