首页
社区
课程
招聘
一个在MFC中使用_AfxBegingThred()的问题[求助]
发表于: 2007-2-10 00:11 4306

一个在MFC中使用_AfxBegingThred()的问题[求助]

2007-2-10 00:11
4306
我用VC6.0写了一个关于多线程的小程序,在_AfxBegingThred()的调用上出了一点问题.我如果在MyDlg.h中的MyDlg类中声明线程函数的原形:UINT MyThread(LPRARM lprarm),在MyDlg.cpp中写函数体,编译器报错说_AfxBegingThred()的第一参数类型不对(即我不能把MyThread传递给_AfxBegingThred()).若是把UINT MyThread(LPRARM lprarm)声明和函数体都放在MyDlg.cpp,_AfxBegingThred()参数类型是不报错了,但是我不能在MyThread(LPRARM lprarm)中调用我在对话框中设定的变量如:m_edit,m_button等类似的变量.我该怎么处理呢?(不知我是否表达明白了?)
谢谢各位!

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 216
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
参看MSDN

AfxBeginThread

This function creates a new thread. The first form of AfxBeginThread creates a worker thread. The second form creates a user-interface thread.

AfxBeginThread creates a new CWinThread object, calls its CreateThread function to start executing the thread, and returns a pointer to the thread. Checks are made throughout the procedure to make sure all objects are deallocated properly should any part of the creation fail. To end the thread, call AfxEndThread from within the thread, or return from the controlling function of the worker thread.




CWinThread* AfxBeginThread(
AFX_THREADPROC pfnThreadProc,
LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
CWinThread* AfxBeginThread(
CRuntimeClass* pThreadClass,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );



Parameters

pfnThreadProc
Points to the controlling function for the worker thread. Cannot be NULL. This function must be declared as follows:
UINT MyControllingFunction( LPVOID pParam );

pParam
Parameter to be passed to the controlling function as shown in the parameter to the function declaration in pfnThreadProc.



1,从MSDN 可以看出 声明的线程函数 原型是 UINT ThreadFuntion(LPVOID pParam)

你的声明参数错误

2,调用线程函数AfxBeginThread  我们可以看出,第一个线程函数名,第二个可以设置为NULL,其他参数都有缺省值,你可以不考虑!

3,至于为什么不能调用你对话框中设置的变量,我想不用说了,你再看看C++的概念!

4,既然使用MFC,最好装一个MSDN,这样遇到困难,都可以找到方法!

注: 可能有说错的地方,谢谢改正!
2007-2-10 10:30
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
谢谢楼上的回复.我先声明一下,上面线程函数的函数原形在我的程序里我声明的是UINT ThreadFuntion(LPVOID pParam)这个样子,上面是当时的笔误(不好意思!).我在调用AfxBeginThread()是传的参数也的确是第一个是线程函数的地址第二个为空.至于为什么不能用对话框中设置的变量我也知道原因.我就是不知道要怎样解决!
还望大家多多指教!
2007-2-12 14:20
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
最初由 haizzz 发布
谢谢楼上的回复.我先声明一下,上面线程函数的函数原形在我的程序里我声明的是UINT ThreadFuntion(LPVOID pParam)这个样子,上面是当时的笔误(不好意思!).我在调用AfxBeginThread()是传的参数也的确是第一个是线程函数的地址第二个为空.至于为什么不能用对话框中设置的变量我也知道原因.我就是不知道要怎样解决!
还望大家多多指教!


声明全局变量!  
关于某个控件的使用,不是一定要给于绑定一个变量,可以使用一些API
如:
GetDlgItem(ID)->SetWindowText(TEXT);
若TEXT为全局变量,大家都可以使用!

PS:说错地方,望谅解!
2007-2-12 16:23
0
游客
登录 | 注册 方可回帖
返回
//