drichards,
attached are snippets of my class .h and .cpp
I added __stdcall to my function decl in my .h file and recompiled but I got the same errors. Obviously, I'm doing it wrong.
Thank you for looking into it.
Main Topics
Browse All TopicsI have a .cpp file that I found online which calls a CreateThread instance as follows given under the code section as original.cpp
The program runs fine when I compile it as a W32-console application.
I am however trying to change it to a class so I can make use of this functionality in a different program that I want to write.
In my classname.h file, when I comment this function (remove it from the class), I get a list of LNK2001: unresolved external symbol errors.
If I keep it as a member of that class, however, I get the following message everytime I try to call the CreateThread
--------------------------
error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)'
None of the functions with this name in scope match the target type
--------------------------
Can somebody please tell me what I'm missing out on???
Thank you
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You have a couple of problems.
If you want "function" to be the ThreadProc, you should either a) Make it a static function in the class and put "classname::" in front of "function" in the cpp file declaration of function or b) Remove the definition of "function" from the class and leave it as a global function in the cpp.
Right now you've got a mismatch in that you define "function" in the classname header but do not actuall implement the class method. Also, it is not static in the class.
Finally, are you sure WINAPI is defined? If you fix the function and still get the __stdcall error, try putting __stdcall in explicitly.
drichards,
thanks for that. Do you mean like this? I did try both the methods (separately of course) and I get the errors that I mentioned in my first post.
I am currently not at my desk to try out the
a. static part
b. if (a) does not work then __stdcall
scenarios. I will update as soon as I get back.
Appreciate all of your help!
If you need a visual, here are your choices. Notice that I also pass "this" to the ThreadProc in callingfunction. This is because function cannot be a non-static method, so it is usually necessary to pass in an instance of the context object. The ThreadProc, "function" in this case, can be nothing more than a cast of the lpParameter to the correct type, classbane in this case, and then a call to the instance method that actually does the work.
Not really. If the only context you need is the socket, there's no real reason to create a class to do anything. Typically the socket itself is only part of the context. There's also protocol information, transaction data, and connection state as part of the context. The object passed in to the thread as a parameter typically provides access to all this other information.
No reason you can't create a class and pass just the socket as context, but there's no real need if that's the extent of it.
Business Accounts
Answer for Membership
by: drichardsPosted on 2008-12-19 at 21:42:31ID: 23217290
It looks like you did not carry the __stdcall (or WINAPI) to the thread function when you created the class. The thread function needs to be a static method or a global function. In either case it need to be declared __stdcall if that is not the default calling convention in your project.
What does the code look like in your refactored version?