下面是一小段程序,但是编译出错了
void CMyFormView::Run()
{
}DWORD WINAPI CMyFormView::RunThread(LPVOID lpParameter)
{
Run();
return 0;
}void CMyFormView::OnButtonT()
{
CreateThread( NULL, 0, RunThread, NULL, 0, NULL );}
这是一个大概的框架,但是编译错误如下:
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刚刚学习,还不太明白,请教一下原因,如何修改?
void CMyFormView::Run()
{
}DWORD WINAPI CMyFormView::RunThread(LPVOID lpParameter)
{
Run();
return 0;
}void CMyFormView::OnButtonT()
{
CreateThread( NULL, 0, RunThread, NULL, 0, NULL );}
这是一个大概的框架,但是编译错误如下:
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刚刚学习,还不太明白,请教一下原因,如何修改?
成员函数隐藏了参数this,比需要的多
error C2352: 'CMyFormView::Run' : illegal call of non-static member function难道都要定义为static类型吗?
class A
{
public:
....
static DWORD CALLBACK ThreadProc(void *lpVoid);
...
};
{
CString str = m_ColListCtrl.GetItemText(2, 4);
} DWORD WINAPI CMyFormView::RunThread(LPVOID lpParameter)
{
Run();
return 0;
} void CMyFormView::OnButtonT()
{
CreateThread( NULL, 0, RunThread, NULL, 0, NULL ); } 编译的时候报错,
error C2352: 'CMyFormView::Run' : illegal call of non-static member function
需要把Run()定义为static才行,而且需要把run()中调用的变量和函数都定义为static类型,有点麻烦,
哪位高人有别的方式可以调用run();不需要把run()定义为static类型;
给指点一下,多谢!
如果我描述的不清楚,请指出。
{
CString str = m_ColListCtrl.GetItemText(2, 4);
} DWORD WINAPI CMyFormView::RunThread(LPVOID lpParameter)
{ CMyFormView* pview = (CMyFormView*)lpParameter;
pview->Run();
return 0;
} void CMyFormView::OnButtonT()
{
CreateThread( NULL, 0, RunThread, this, 0, NULL ); }
static DWORD WINAPI CMyFormView::RunThread(LPVOID lpParameter)