CreateThread problem

Hello

I have function wich I want to run in thead, the function looks like this:
void MainDlg::Recieve(LPVOID msg)
(it belongs to dialog class),
when I do:

HANDLE hThreadRecieve ;
hThreadRecieve = CreateThread(                        NULL,
            0,
            (LPTHREAD_START_ROUTINE)Recieve,                              (LPVOID)&msg,                        THREAD_QUERY_INFORMATION,                         &dwThreadID);

And then I have compiler error:
'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)'

Why?
It workes in Console Application but not in MFC

Thanks
YuliaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
WynConnect With a Mentor Commented:
hmm
0
 
WynCommented:
Your receive function must have this type declartion:
DWORD WINAPI ThreadProc(  LPVOID lpParameter   // thread data);

Change it to static and add WINAPI.

Regards
W.Yinan
0
 
WynCommented:
static WINAPI DWORD MainDlg::Recieve(LPVOID msg)

Running?
:)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Declare Ur thread function in dlg.h as a public as

static UINT Receive(LPVOID pParam );

Then write the function as
UINT ..Dlg::Receive(LPVOID s)
{
....
....
}

Then while spawning use
LPVOID s;
AfxBeginThread(Receive, s);

Try it out.

VinExpert
0
 
WynCommented:
Oops:)

static DWORD WINAPI MainDlg::Recieve(LPVOID msg)

Running?
:)
 
0
 
WynCommented:
no MFC,VinExpert:)
0
 
YuliaAuthor Commented:
got this error

error C2724: 'Recieve' : 'static' should not be used on member functions defined at file scope
0
 
YuliaAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.