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

  • SEARCH
  • Home
  • 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 106421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:35:38+00:00 2026-05-11T01:35:38+00:00

i want to do this simple piece of code work. #include <iostream> #include <windows.h>

  • 0

i want to do this simple piece of code work.

#include <iostream> #include <windows.h>       void printSome (int i)     {         std::cout << i << std::endl;     }      void spawnThread (void (*threadName)(int i))     {         CreateThread              (                 0,      // default security attributes                 0,          // use default stack size                  (LPTHREAD_START_ROUTINE)threadName,  // thread function name                 (LPVOID)i,          // argument to thread function                  0,          // use default creation flags                  0       // returns the thread identifier              );       }      int main ()     {         spawnThread(printSome(155));     } 

i am on windows, using vs. Any help will be greatly appriciated.

  • 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. 2026-05-11T01:35:39+00:00Added an answer on May 11, 2026 at 1:35 am

    Personally, I wouldn’t consider passing in a function pointer like you are trying to do as very C++ like. That’s coding C in C++

    Instead, I’d wrap that thing in a class. The big advantage there is you can just override the class to have however many members you want, rather than having to perform greazy casting tricks to get at your parameters every time.

    The code’s a little long-winded, so I pushed it to the end. But what it lets you do is something like this:

       class print_some : public basic_thread {     private:        int i;     public:             print_some (int i) : i(i) {};        action_callback () {           std::cout << i << std::endl;        }     }     int main () {        print_some printer (155);     } 

    Here’s some exerpted example code from one of our classes that does this:

    class basic_thread :  { public:    basic_thread(); protected:    unsigned long m_ThreadId;     virtual void action_callback () {};     // Internal routine used to bridge between OS callback format and     // action_callback. *Must* be static for the OS.    static unsigned long __stdcall self_calling_callback (void *parameter); } 

    …and in the .cpp:

    unsigned long __stdcall basic_thread::self_calling_callback (void *parameter) {    if (parameter) {       basic_thread * thread = reinterpret_cast<basic_thread *>(parameter);       thread->action_callback();    }    return 0; // The value returned only matters if someone starts calling GetExitCodeThread              // to retrieve it. }  basic_thread::basic_thread () {    // Start thread.    m_Handle = CreateThread(NULL,                            0,                            self_calling_callback,                            (PVOID)this,                            0,                            &m_ThreadId );    if( !IsHandleValid() )       throw StartException('CreateThread() failed', GetLastError());  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Eclipse is the best IDE to use for both Python… May 11, 2026 at 11:39 pm
  • Editorial Team
    Editorial Team added an answer .csproj, assemblyinfo.cs, plus your code and solution (.sln) file. Also,… May 11, 2026 at 11:39 pm
  • Editorial Team
    Editorial Team added an answer No, it does not. It's a part of the VM… May 11, 2026 at 11:39 pm

Related Questions

I'm starting to kick Silverlight around (although it currently feels the other way around)
A couple of years ago the media was rife with all sorts of articles
I have a JavaScript widget (a piece of embedded JS and HTML code) that's
Given a string like this: <a href=http://blah.com/foo/blah>This is the foo link</a> ... and a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.