• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 907
  • Last Modified:

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
0
Yulia
Asked:
Yulia
  • 5
  • 2
1 Solution
 
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:
hmm
0
 
WynCommented:
static WINAPI DWORD MainDlg::Recieve(LPVOID msg)

Running?
:)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now