Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6193811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:11:06+00:00 2026-05-24T03:11:06+00:00

I have a class such as : class MyStreamReader { public: MyStreamReader(MyPramameter myPram) {…..}

  • 0

I have a class such as :

class MyStreamReader
{
public:
    MyStreamReader(MyPramameter myPram) {.....}
    ~MyStreamReader() {}

    DWORD WINAPI  ReaderThread(LPVOID *lpdwThreadParam ) 

    {

       //....
    }
};

and i want to call ReaderThread with WinAPI CreateThread. But CreateThread wants ReaderThread function wants a static function.

In some forms it is said that this is possible with boost library such as :

CreateThread(NULL, 0, boost::bind(&MyStreamReader::ReaderThread,this),

(void*)&myParameterObject), 0, NULL);

But i got compilation error:

'CreateThread' : cannot convert parameter x from 'boost::_bi::bind_t<R,F,L>' 

to 'LPTHREAD_START_ROUTINE'

So as a result my questions:

  1. Is it possible to call non-static function of a class from
    CreateThread using boost lib(or any other method)
  2. If not any C++ THREADing librray you may recomend(for visual C++) which i can call-run non static member function of a class as a thread?

Best Wishes

Update:

So first question: It seesm that it is impossible to call non-static c++ member function from CreateThread win API…

So any recomandations for C++ Multithreading lib whic is possible to call non-static functions as threads…

Update 2:
Well i try boost thread lib…seems it works…

MyStreamReader* streamReader = new MyStreamReader(myParameters);


boost::thread GetStreamsThread

   ( boost::bind( &MyStreamReader::ReaderThread, streamReader ) );

or (no need for bind)

boost::thread GetStreamsThread(&MyStreamReader::ReaderThread, streamReader);

AND in order to use boost::thread i update my class definition as:

class MyStreamReader
  {
    public:
        MyStreamReader(MyPramameter myPram) {.....}
        ~MyStreamReader() {}

        void ReaderThread()
        {

           //....
        }
  };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:11:06+00:00Added an answer on May 24, 2026 at 3:11 am

    One common answer to this is to use a static “thunk”:

    class Worker
    {
        public :
            static DWORD Thunk(void *pv)
            {
                Worker *pThis = static_cast<Worker*>(pv);
                return pThis->DoWork();
            }
    
            DWORD DoWork() { ... }
    };
    
    ...
    
    int main()
    {
        Worker worker;
        CreateThread(NULL, 0, &Worker::Thunk, &worker);
    }
    

    You can, of course, pack more parameters into your call to pv. Just have your thunk sort them out correctly.

    To answer your question more directly, boost::bind doesn’t work with the Winapi that way. I would advise using boost::thread instead, which does work with boost::bind (or, if you have a C++0x compiler, use std::thread with std::bind).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a base class such that public abstract class XMLSubscription <T extends
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
So let's say we have a domain object such as the following public class
In AS3, if I have a class such: public class dude { //default value
I have a class structure such as following for storing static final constants: public
If I have a class defined as such: class classWithInt { public: classWithInt(); ...
I have a ravendb class like such: public class Student { public string Id
I have such a problem. I have class, in which I make a call
If I have class names such as left, right, clear and xhtml like <a
I have a class hierarchy as such: +-- VirtualNode | INode --+ +-- SiteNode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.