?
Solved

Win32-API: CreateThread

Posted on 2003-03-23
5
Medium Priority
?
835 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
2 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 expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Suggested Courses

621 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