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 5982873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:08:59+00:00 2026-05-22T22:08:59+00:00

In examples on the web, calls to CreateThread typically pass a pointer to a

  • 0

In examples on the web, calls to CreateThread typically pass a pointer to a struct for LPVOID lpParameter, and you use that pointer to access the struct itself.

#include <Windows.h>
#include <stdio.h>

struct Point
{
  float x,y,z ;
} ;

DWORD WINAPI threadStartPoint( LPVOID data )
{
  Sleep( 1000 ) ;
  Point *p = (Point*)data ;
  printf( "%f %f %f\n", p->x, p->y, p->z ) ;
  puts( "Thread job done" ) ;
  return 0 ;
}

// From main
int main()
{
  DWORD threadId ;
  Point p ;
  p.x=2, p.y=3, p.z=4 ;
  HANDLE handle = CreateThread( 0, 0, 
    threadStartPoint,
    (LPVOID)&p,
    0,  // ?? I think I should be using this parameter</b>
    &threadId
  ) ;

  if( !handle )
  {
    // Thread creation failed
    puts( "start fail\n" );
  }
  else
  {
    printf( "started on threadid=%d\n", threadId ) ;
  }

  WaitForSingleObject( handle, 2000 ) ; // wait up to 2000 ms for the other thread to complete before moving on

  puts( "main thread Exiting.." ) ;
  //system( "pause" ) ;
}

I’m finding this to be somewhat of an inconvenience, since you have to make sure that struct exists, and make sure it is properly destroyed when the thread is finished executing.

I’d like to start my thread, but passing normal stack arguments ie automatic variables, or perhaps, the struct itself to the thread start routine:

DWORD threadStartPointFuncStyleIWant( Data d ) ;

So my questions are really:

  • For a thread start point (CreateThread), are we restricted to a function with prototype of the form:
DWORD validThreadFunc( LPVOID pParamStruct ) ;
  • Or can we start a thread on functions like
DWORD threadFunc1( int p1, int p2 ) ;
DWORD threadFunc2( Data d ) ;
  • 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-22T22:08:59+00:00Added an answer on May 22, 2026 at 10:08 pm

    CreateThread accepts only one type of function, the one that takes a single LPVOID parameter. There’s no way to communicate to kernel32.dll, which is the code that calls your thread function, that it should call it with any other parameter list. The kernel always calls the function the same way.

    You’ll just have to continue doing it the same way everyone else does. Allocate the structure on the heap, pass the pointer to your thread routine, and then free it before returning from your thread routine. That is, ownership passes from the originating thread to the new thread. Once the new thread gets ownership, you can use a smart pointer like shared_ptr to make sure it gets freed however you leave the thread.

    You’re welcome to pass another function pointer in that struct, or pass an object with methods of its own. Then your thread procedure becomes nothing more than something to unpack the LPVOID parameter and dispatch to the other function pointer or method, where you do all the real work for the thread.

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

Sidebar

Related Questions

What makes Python stand out for use in web development? What are some examples
I have an ASP.NET MVC web application that makes REST style web service calls
I'm scaling a CGImageRef . I found various code examples on the web that
Are there any good examples out there of how the following web service would
Web parts seem to be used extensively in Sharepoint related development, but examples of
I would like to look at some examples of some good form layouts (web-based)
I'm looking for tips, suggestions, advice or examples of applications build using Google's Web
Say for example you're getting a web app project that interacts with a database.
I have developed a small C# form application which calls a web service. Everything
I've been able setup the oAuth calls to get the users access Token following

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.