创建线程出错

zhaolixin007 2010-09-06 08:54:03
问题现象:
1:使用AfxBeginThread函数:
使用如下语句:
HANDLE hmulti;
hmulti = AfxBeginThread(ThreadProc1,0,0,0,NULL);
我的线程响应函数如下:
UINT ThreadProc1()
{

return 0;
}
编译过程中出现:
error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void)' to 'unsigned long (__stdcall *)(void *)'
None of the functions with this name in scope match the target type
问题

2: 使用CreateThread

使用如下语句:
HANDLE hmulti;
hmulti =CreateThread(NULL,0,ThreadProc1,this,0,NULL);
我的线程响应函数如下:
UINT ThreadProc1()
{

return 0;
}
编译过程中出现:
error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void)' to 'unsigned long (__stdcall *)(void *)'
None of the functions with this name in scope match the target type
Error executing cl.exe.

请有相应经验的兄弟解决下这个问题,谢谢。



...全文
94 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
youdaping777 2010-09-06
  • 打赏
  • 举报
回复
1.UINT ThreadProc1( LPVOID pParam );//AfxBeginThread
2. UINT WINAPI ThreadProc1(LPVOID pParam);//CreateThread
//UINT __stdcall ThreadProc1(LPVOID pParam);
SEESEECN 2010-09-06
  • 打赏
  • 举报
回复
参数问题
lazy_2010 2010-09-06
  • 打赏
  • 举报
回复
对于 AfxBeginThread,不要加 WINAPI;对于 CreateThread 需要加 WINAPI
zhaolixin007 2010-09-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hucailai 的回复:]
参数错误

UINT WINAPI ThreadProc1(PVOID pParam);


UINT __stdcall ThreadProc1(PVOID pParam);
[/Quote]

改成如下:
创建: CWinThread *pTh;
pTh =AfxBeginThread(ThreadProc1,this,0,0,0,NULL);
调用:

UINT WINAPI ThreadProc1(PVOID pThreadParam)
{
return 0;
}

报错:'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
guobin190 2010-09-06
  • 打赏
  • 举报
回复
恩 调用约定和参数问题
hucailai 2010-09-06
  • 打赏
  • 举报
回复
参数错误

UINT WINAPI ThreadProc1(PVOID pParam);


UINT __stdcall ThreadProc1(PVOID pParam);
lazy_2010 2010-09-06
  • 打赏
  • 举报
回复
应该是

UINT WINAPI ThreadProc1(void*);

或者

UINT __stdcall ThreadProc1(void*);
lazy_2010 2010-09-06
  • 打赏
  • 举报
回复
UINT WINAPI ThreadProc1();

或者

UINT __stdcall ThreadProc1();


ouyh12345 2010-09-06
  • 打赏
  • 举报
回复
ThreadProc1函数的声明格式是有规矩的,调用约定得是__stdcall,参数是void *

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧