We help IT Professionals succeed at work.

CreateThread problem

Yulia
Yulia asked
on
929 Views
Last Modified: 2013-11-20
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
Comment
Watch Question

Wyn

Commented:
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
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Wyn

Commented:
static WINAPI DWORD MainDlg::Recieve(LPVOID msg)

Running?
:)
Vinayak KumbarSr Program Manager

Commented:
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
Wyn

Commented:
Oops:)

static DWORD WINAPI MainDlg::Recieve(LPVOID msg)

Running?
:)
 
Wyn

Commented:
no MFC,VinExpert:)

Author

Commented:
got this error

error C2724: 'Recieve' : 'static' should not be used on member functions defined at file scope

Author

Commented:
Thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.