loop speed
-
Please also specify if you are using MFC or Win32. Is it a dialog-based application? And Is the worker() function a member of your class? this is this.
-
I assume this is your worker function: void CMyDlg::Worker() { while (m_bWorking) { //processing here. } } In your header file: HANDLE m_hThread; bool m_bWorking; static DWORD __stdcall Thread(LPVOID lpVoid); In your .cpp file: DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid) { CMyDlg* parent = (CMyDlg*)lpVoid; parent->Worker(); return 0; } void CMyDlg::OnButtonStart()//your button handler function. { m_bWorking = TRUE; m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); ResumeThread(m_hThread); } void CMyDlg::OnButtonSuspend()//pause it { SuspendThread(m_hThread); } void CMyDlg::OnButtonResume()//resume it { ResumeThread(m_hThread); } void CMyDlg::OnButtonStop()//stop it { m_bWorking = false; } I hope that helps. this is this.
-
I assume this is your worker function: void CMyDlg::Worker() { while (m_bWorking) { //processing here. } } In your header file: HANDLE m_hThread; bool m_bWorking; static DWORD __stdcall Thread(LPVOID lpVoid); In your .cpp file: DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid) { CMyDlg* parent = (CMyDlg*)lpVoid; parent->Worker(); return 0; } void CMyDlg::OnButtonStart()//your button handler function. { m_bWorking = TRUE; m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); ResumeThread(m_hThread); } void CMyDlg::OnButtonSuspend()//pause it { SuspendThread(m_hThread); } void CMyDlg::OnButtonResume()//resume it { ResumeThread(m_hThread); } void CMyDlg::OnButtonStop()//stop it { m_bWorking = false; } I hope that helps. this is this.
-
m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); C:\Program Files\Microsoft Visual Studio\MyProjects\wordlist\wordlistDlg.cpp(230) : error C2065: 'id' : undeclared identifier its about time to give up
-
You must have seen in my first post that: unsigned long id; or DWORD id; Please have a look at this MSDN url also: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createthread.asp[^] this is this.
-
unsigned long id; or DWORD id; either of them will give another error if i try them and i cant even come close of making since of the web page :mad: just shoot me
First thing to do is Be Calm. Read some poetry. Next, declaring a variable does not give errors. Make sure you declare it: DWORD id; before CreateThread() function call. And try Rebuild All from the build menu. If that does not solve the problem, you can post the error that Visual Studio gives. this is this.
-
First thing to do is Be Calm. Read some poetry. Next, declaring a variable does not give errors. Make sure you declare it: DWORD id; before CreateThread() function call. And try Rebuild All from the build menu. If that does not solve the problem, you can post the error that Visual Studio gives. this is this.
C:\Program Files\Microsoft Visual Studio\MyProjects\wordlist\wordlistDlg.cpp(231) : 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 DWORD id; m_bWorking = TRUE; m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); ResumeThread(m_hThread); that was with the build all ps. i am calm lol
-
C:\Program Files\Microsoft Visual Studio\MyProjects\wordlist\wordlistDlg.cpp(231) : 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 DWORD id; m_bWorking = TRUE; m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); ResumeThread(m_hThread); that was with the build all ps. i am calm lol
Did you declare the Thread function in the class? It should be like this: static DWORD __stdcall Thread(LPVOID lpVoid); In the implementation file: DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid) { ... And "CMyDlg" is the name of your dialog class. Change that with the real name. Hope that helps. this is this.
-
Did you declare the Thread function in the class? It should be like this: static DWORD __stdcall Thread(LPVOID lpVoid); In the implementation file: DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid) { ... And "CMyDlg" is the name of your dialog class. Change that with the real name. Hope that helps. this is this.
-
Note that CMyDlg is the placeholder of your class-name. e.g, if you made a dialog-based app called Hello, then your dialog class-name will be "CHelloDlg". When you declare a function, it means go to the header file (*.h), and write the declaration line there: e.g, in HelloDlg.h: HANDLE m_hThread; bool m_bWorking; static DWORD __stdcall Thread(LPVOID lpVoid); //------------- declaration ends here. Now open the associated .cpp file e.g, HelloDlg.cpp and write the complete functions there: DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid) { ..... blah blah. And be sure to read a good book on Visual C++. this is this.
-
Note that CMyDlg is the placeholder of your class-name. e.g, if you made a dialog-based app called Hello, then your dialog class-name will be "CHelloDlg". When you declare a function, it means go to the header file (*.h), and write the declaration line there: e.g, in HelloDlg.h: HANDLE m_hThread; bool m_bWorking; static DWORD __stdcall Thread(LPVOID lpVoid); //------------- declaration ends here. Now open the associated .cpp file e.g, HelloDlg.cpp and write the complete functions there: DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid) { ..... blah blah. And be sure to read a good book on Visual C++. this is this.
-
I assume this is your worker function: void CMyDlg::Worker() { while (m_bWorking) { //processing here. } } In your header file: HANDLE m_hThread; bool m_bWorking; static DWORD __stdcall Thread(LPVOID lpVoid); In your .cpp file: DWORD __stdcall CMyDlg::Thread(LPVOID lpVoid) { CMyDlg* parent = (CMyDlg*)lpVoid; parent->Worker(); return 0; } void CMyDlg::OnButtonStart()//your button handler function. { m_bWorking = TRUE; m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); ResumeThread(m_hThread); } void CMyDlg::OnButtonSuspend()//pause it { SuspendThread(m_hThread); } void CMyDlg::OnButtonResume()//resume it { ResumeThread(m_hThread); } void CMyDlg::OnButtonStop()//stop it { m_bWorking = false; } I hope that helps. this is this.
khan++ wrote: m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); Use
AfxBeginThread()
with MFC applications.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
i narrowed it down i think. if i leave DWORD id; m_bWorking = TRUE; m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); ResumeThread(m_hThread); like it is it errors if i //ResumeThread(m_hThread); no error but the program dont run either so im stuck again. error: debug assertion failed file: wincore.cpp line: 890 X| X| X| X|
-
i narrowed it down i think. if i leave DWORD id; m_bWorking = TRUE; m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST); ResumeThread(m_hThread); like it is it errors if i //ResumeThread(m_hThread); no error but the program dont run either so im stuck again. error: debug assertion failed file: wincore.cpp line: 890 X| X| X| X|
locoone wrote: m_hThread = CreateThread(NULL,0,Thread,this,CREATE_SUSPENDED,&id); See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown