Classes + Threads

I had a fully working multi-threaded windows application.
Unfortunately, I had to convert it to be Object Oriented,
and now I have problems with my CreateThread calls.
I had some module and I wrapped all it's functions
in a class, and I want to get the same functionality.
But when I call CreateThread from one of the methods
to create a new thread with some oter method, I get next error:
cannot convert parameter 3 from 'unsigned long (__stdcall *(void *))(void *)' to 'unsigned long (__stdcall *)(void *)
All this worked before both functions were inserted into the class. Any suggestions?

P.S.
Called function declared as:
DWORD WINAPI class_name::function_name(LPVOID lpvThreadParam);
i.e.

Thanks in advance
LVL 1
finikAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Define it as a static member function. A non-static member function has an implicit parameter, which is the this pointer. Therefore, the function prototype does not match the one required by CreateThread.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chensuCommented:
If you are going to call C run-time routines from a program built with LIBCMT.LIB, you must start your threads with the _beginthread function. Do not use the Win32 functions ExitThread and CreateThread.
0
finikAuthor Commented:
1. I tried the static function, but static couldn't access any no static functions and variables. I tried this->function_name as well, but is seems to lead to the same result as w/out the this->.

2. What's wrong about CreateThread and ExitThread?
What c run-time routines are we talking about? I use ExitThread a lot in my program.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

finikAuthor Commented:
Sorry, the error is:
cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)'
and not the one stated in the question.
0
chensuCommented:
1. You may pass the this pointer as a parameter of the thread controlling function.

2. Any C run-time routines, such as strcpy.

C Run-Time Library Functions for Thread Control
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/devprods/vs6/visualc/vccore/_core_c_run.2d.time_library_functions_for_thread_control.htm

Library Support for Multithreading
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/devprods/vs6/visualc/vccore/_core_library_support_for_multithreading.htm
0
finikAuthor Commented:
Thanks, I'll through a look at the links.
But it seems, like my problems are much bigger, and not as technical as it looked in the question in the first place. My program was totally multithreaded. It was a socks proxy/firewall,
and there was like socks_listener, a lot of socks_threads(every client gets one per connection, http_listener, a lot of http_threads (same thing)..and so on. Now, when I was told to rewrite it OOP way, I thought of the whole! http module as an object. But, as I understand now from what I've seen, it couldn't be 1 object and split into different threads (according to methods http::http_listener and http::http_thread). Am I right? Like I saw in MSDN, if you want to create a thread in MFC/OOP environment, you need a controlling function and to provide an object as a parameter. But that means that I have to split to smaller
objects like (http_listener, http_thread). But then it doesn't make sence either, since I get a full program of small objects, each one of them with only 1 function (I can even make it a constructor). Am I missing something in OOP concept?
0
chensuCommented:
You don't have to split it. You may add some (static or non-static) member variables to indicate the status. These will be passed along with the object. Since I don't see the entire view of your project, it is hard for me to give any useful suggestion. Sorry.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.