AfxBeginThread
-
Can I pass a parameter to the function if I have a worker thread and use AfxBeginThread?
-
Can I pass a parameter to the function if I have a worker thread and use AfxBeginThread?
CWinThread* AfxBeginThread(
AFX_THREADPROC pfnThreadProc,
LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);pParam Parameter to be passed to the controlling function as shown in the parameter to the function declaration in pfnThreadProc.
Cédric Moonen Software developer
Charting control -
Can I pass a parameter to the function if I have a worker thread and use AfxBeginThread?
-
CWinThread* AfxBeginThread(
AFX_THREADPROC pfnThreadProc,
LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);pParam Parameter to be passed to the controlling function as shown in the parameter to the function declaration in pfnThreadProc.
Cédric Moonen Software developer
Charting controlI've also read that but I still don't understand??!!?
-
I've also read that but I still don't understand??!!?
Then ask a clear question. What is your problem ?? We cannot guess it. Why don't you just pass your data (as a pointer for example) using this parameter ?
Cédric Moonen Software developer
Charting control -
Then ask a clear question. What is your problem ?? We cannot guess it. Why don't you just pass your data (as a pointer for example) using this parameter ?
Cédric Moonen Software developer
Charting controlThis is my controling function
UINT CMina_sView::run(LPVOID p) { CMina_sView * me = (CMina_sView *)p; me->ascultarea(); return 0; }
And this is how I start the threadvoid CMina_sView::OnList() { running = TRUE; AfxBeginThread(run, this); }
I want to pass a paramater to ascultarea. How do i do it? -
This is my controling function
UINT CMina_sView::run(LPVOID p) { CMina_sView * me = (CMina_sView *)p; me->ascultarea(); return 0; }
And this is how I start the threadvoid CMina_sView::OnList() { running = TRUE; AfxBeginThread(run, this); }
I want to pass a paramater to ascultarea. How do i do it?You already passed a parameter to your thread: it's the address of the class (the this parameter). So, you cannot pass two parameters. But, why do you want to pass a parameter to this function ? Why don't you just have a member variable that hold this variable so that the function ascultarea can use it ?
Cédric Moonen Software developer
Charting control -
You already passed a parameter to your thread: it's the address of the class (the this parameter). So, you cannot pass two parameters. But, why do you want to pass a parameter to this function ? Why don't you just have a member variable that hold this variable so that the function ascultarea can use it ?
Cédric Moonen Software developer
Charting controlThe OnList is a menu item that opens a dialog in which I can select smth a i hold that in dlg.m_sel. I want to be able to pass dlg.m_sel to ascultarea.
-
The OnList is a menu item that opens a dialog in which I can select smth a i hold that in dlg.m_sel. I want to be able to pass dlg.m_sel to ascultarea.
tanarnelinistit wrote:
I can select smth a i hold that in dlg.m_sel
:confused: Please make a little effort on the spelling because I cannot understand (english is not my mother tongue). When are you opening the dialog ? Before or after spawning the thread ? If it is after, then why don't you simply take this value (dlg.m_sel) and store it into a member variable of CMina_sView ? Then in your thread, as you call the function ascultarea, as it is inside the SAME class, you don't need to pass it to the function. The function can simply get it from the member variable. I think the problem is that you don't know what you are doing. You probably found some snippet of code to start the thread but you don't understand the mechanics beyond that. Am I right ? Then, I cannot explain you in details because the subject is fairly too large. (And I already provided you with the solution).
Cédric Moonen Software developer
Charting control -
tanarnelinistit wrote:
I can select smth a i hold that in dlg.m_sel
:confused: Please make a little effort on the spelling because I cannot understand (english is not my mother tongue). When are you opening the dialog ? Before or after spawning the thread ? If it is after, then why don't you simply take this value (dlg.m_sel) and store it into a member variable of CMina_sView ? Then in your thread, as you call the function ascultarea, as it is inside the SAME class, you don't need to pass it to the function. The function can simply get it from the member variable. I think the problem is that you don't know what you are doing. You probably found some snippet of code to start the thread but you don't understand the mechanics beyond that. Am I right ? Then, I cannot explain you in details because the subject is fairly too large. (And I already provided you with the solution).
Cédric Moonen Software developer
Charting control1)I knew I should've studied french a little more in highschool. 2)I started programing in VC++ just one month ago but I've read and understood anything I could in one month. 3) I open the dialog and then I spawn the thread.
-
1)I knew I should've studied french a little more in highschool. 2)I started programing in VC++ just one month ago but I've read and understood anything I could in one month. 3) I open the dialog and then I spawn the thread.
I already explained you the solution 2 times. Once more won't help you to understand it better. After one month of studying C++, it is not a good idea to jump directly to thread manipulation (even more if you didn't know a programming language before). The only advice I can give you is: start slowly. Try to find a good book or course and start to learn the basics first. Otherwise, you'll screw up everything and you'll be really disgusted for life.
Cédric Moonen Software developer
Charting control -
I already explained you the solution 2 times. Once more won't help you to understand it better. After one month of studying C++, it is not a good idea to jump directly to thread manipulation (even more if you didn't know a programming language before). The only advice I can give you is: start slowly. Try to find a good book or course and start to learn the basics first. Otherwise, you'll screw up everything and you'll be really disgusted for life.
Cédric Moonen Software developer
Charting controlOk. Thanks a lot. Although I feel a little bit disapointed now, I got your point.