CreateThread

/*definition*/
DWORD WINAPI CMailManagerDlg::CheckIt(LPVOID pParam)

/*CheckIt() is the function which should be called on different thread. There is no syntax error but new thread is not getting created.Please check the parameters passed to CreateThread as function is not working sucessfully*/

/*call to the thread function*/
 threadhandle = CreateThread(0,0,CheckIt,(LPVOID)(-2),0,lpThreadId);

devayaniAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
abdijConnect With a Mentor Commented:
I donot know how you managed to get the code compiled. When i tried to make the ThreadProc a member function of the Dialog class it gave me an error

"'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"

Any way, even otherwise you can get your thread executed by making it global function.

Secondly you have not mentioned if you are handling the the default parent member function of the Dialog class(Eg: in the OnOk function CDialog::OnOK()). If you have done so comment it. The worked atleast for me.
0
 
jhanceCommented:
If your thread uses the C run-time library (which is typical) you should not use CreateThread.  Use beginthread/endthread instead to ensure proper initialization of the RTL.

Anyway, what is the return value to threadhandle?  Is there an error reported?
0
 
mikeblasCommented:
Certainly, you've declared CMailManagerDlg::CheckIt() as a static member of that class, right?

..B ekiM
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
chensuCommented:
1. You should have told us what error messages you got. Never never just say "It does not work" or "It is not working".

2. For MFC applications, you should use AfxBeginThread instead of CreateThread.

3. CheckIt needs to be either a static member function or a global function. This is because a non-static member function has an implicit parameter, which is the this pointer. Thus, it does not match the function prototype required by AfxBeginThread.
0
 
chensuCommented:
You might want to take a look at my article at CodeGuru, which demonstrates how to use AfxBeginThread.

Download a File Using URLDownloadToCacheFile
http://www.codeguru.com/internet/urlfile.shtml
0
 
devayaniAuthor Commented:
There is no error i.e the biggest problem and CreateThread also
returns successful result.
0
 
jhanceCommented:
If, as you say, there is no error then CreateThread is returning you a handle to the newly created thread.  There are only two possibilities with this call:

1) It returns an error
2) It returns a handle to the new thread.

Now perhaps the thread isn't running as you expect but I'd just be speculation on it since you don't seem to want to provide many details about what the problem is.
0
 
mikeblasCommented:
Where does this stand?  It's been about a month since you've told us anything, devayani.

..B ekiM
0
 
abdijCommented:
Hi,

I do have to agree with mikeblas. Please consider at the earliest.

No harm meant.

Thanx
0
 
devayaniAuthor Commented:
Actually I was trying for other problems,but I will try at the earliest
and will inform you.
0
All Courses

From novice to tech pro — start learning today.