子线程调用主线程函数以及变量问题
已经参考了很多朋友的提问以及答案了,现在编译时有以下问题:
error C2673: ‘Action1’: global functions do not have 'this' pointers
请高手详细解释一下其中的调用过程
test.h:
static DWORD Scrap1(); (这里如果不是定义static,就报error C2440: 'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)')
test.cpp:
DWORD Action1()
{
((CBatchScrapDlg*)CWnd::FromHandle(this->m_hWnd))->Scrap();
return 0;
}
void CTestDlg::OnAction()
{
hThread=CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)Action1,
NULL,
0,
NULL);
}
一个朋友说如下结论,我的疑问是:FuncTest() 他在testdlg.h中如何定义
假设你的对话框是CTestDlg,成员是FuncTest()
可以这样用:
((CTestDlg*)CWnd::FromHandle(this->m_hWnd))->FuncTest();