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
Solved

CreateThread problem

Posted on 2000-03-13
8
893 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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

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.

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 94
deburging in oracle form 12 105
modThree challenge 4 96
My project did see openJDK that I installed. What could be the problem 7 151
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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