?
Solved

Win32-API: CreateThread

Posted on 2003-03-23
5
Medium Priority
?
806 Views
Last Modified: 2013-11-20
Hello folks,

I'm trying to create a socket class with MSVC++ 6 that allows a simply handling of network connections. To make connections asynchron I use the select() function to get readable/writable-signals for a socket. For each signal, my application has to create a thread that calls a member function to handle that signal, i.e. to recv() or send() on that socket.I call CreateThread() to open a new thread:

CreateThread(NULL, 0, this->onRecv, (void *)0, 0, &thread)
where the socket class' member function "onRecv" looks as following:
unsigned long WINAPI onRecv(void *);

The compiler gives the error C2440, which says:
"Unable to convert argument 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)'"

Somebody out there with some experience or any help ?

-Ben-
0
Comment
Question by:CWay
[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 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 8189462
Thread function should be global or class static function. Class non-static function contains hidden "this" parameter, this is a reason of compilation error.
If you want to return to non-static class member function, pass pointer to class as lpParameter. In global function cast this value to class pointer and call non-static member function.
0
 

Author Comment

by:CWay
ID: 8190562
Thanks for your help !

After google'ing a bit I found a method to solve my problem. I declared a static thread function that belongs so my socket class. The parameter to the thread function is the pointer to the calling instance of my class (this). It is working fine now.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

777 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