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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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
abdijCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.