Solved

CreateThread problem

Posted on 2000-03-13
8
897 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
0
Comment
Question by:Yulia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2612586
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
 
LVL 5

Accepted Solution

by:
Wyn earned 50 total points
ID: 2612592
hmm
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2612606
static WINAPI DWORD MainDlg::Recieve(LPVOID msg)

Running?
:)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:VinExpert
ID: 2612608
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
 
LVL 5

Expert Comment

by:Wyn
ID: 2612612
Oops:)

static DWORD WINAPI MainDlg::Recieve(LPVOID msg)

Running?
:)
 
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2612614
no MFC,VinExpert:)
0
 

Author Comment

by:Yulia
ID: 2612644
got this error

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

Author Comment

by:Yulia
ID: 2612741
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 97
pre4 challenge 19 114
sumHeights  challenge 17 82
Updating statistics with error notification email in SQL server 4 125
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question