|
|
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.
|
|
|
|
|
it is mfc and dialog and the last im not sure what ya mean
|
|
|
|
|
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
|
|
|
|
|
|
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
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.
|
|
|
|
|
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.
|
|
|
|
|
im so lost now i have no clue
|
|
|
|
|
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.
|
|
|
|
|
yea i know about the CMyDlg name i got it to not give a error when compilling but when run is a bad error but its 6 am im going to bed will post tomorrow
|
|
|
|
|
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
|
|
|
|
|
See here and here for thread information.
"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
|
|
|
|
|
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
|
|
|
|
|
i debug my program in VC6.0. when it is closed, the exception "First-chance exception in F863.exe: 0xC0000005: Access Violation." will appear. and the cursor points to m_pInterface->Release().here are some codes:
void _Release() throw()
{
if (m_pInterface != NULL) {
m_pInterface->Release();
}
}
i define the variant:IApplicationPtr m_Application, and i find the exception occured in m_Application->Release().
here are some codes:
int CF863App::ExitInstance()
{
if (m_Application != 0)
m_Application->Release();
return CWinApp::ExitInstance();
}
how can i resolve it?
|
|
|
|
|
Some possible causes:
a) You didn't initialize m_Application to NULL.
b) You are trying to release it more than it's neeeded.
c) Something else
Maybe if you showed where you initialize (or assign) m_Application, and explain what else you do with it...
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Any Cpu has a special serial number
How can get it's number in MFC?
|
|
|
|
|
Not any CPU does have one, and it has to be enabled in the BIOS.
E.g. the P3 does have a serial number, but the P4 does not have (see http://download.intel.com/design/Xeon/applnots/24161828.pdf[^], p. 17 ("Processor serial number (PSN) is not supported on the Pentium 4 processor or later."))
If you want to access it refer to section 4.1 of this pdf file.
Don't try it, just do it!
|
|
|
|
|
|
How can i change width and height of a Bitmap and save it again?
|
|
|
|
|
Iam Developing Client/Server Application in MFC Using CSockets.I created Server Socket(Serrived From CSocket) and Created One Thread To Listen to the incoming Requests.In Side that thread iam calling Accept()of CSocket.But my Application is Crashing.can you pls help mw regarding this
VamsiDhar.MBC
SoftwareEngineer
|
|
|
|
|
There are some questions:
1. when your app. crashes?
2. where your application crashes?
3. Which App crashes?(client or server)
You must trace what happening in debug mode in both sides.
|
|
|
|