Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create an arglist for _beginthread function

Posted on 2000-03-03
1
Medium Priority
?
506 Views
Last Modified: 2008-02-01
For the beginthread function in the process library for c on windows, I am able to specify an argument list for the function I wish to call when starting the thread.  However, I can get this to work fine when there is one parameter and I pass in, say an int, just this one.  But what happens if I need to pass the function more than one parameter, e.g. an int and a char*?
I have tried to send the function a string containing the variable names created with sprintf, but when debugging the thread that has been called, the parameter values are all nonsense.
0
Comment
Question by:Greystoke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 2580784
There are several ways to accomplish this, however themost common one is to pass a pointer to a data structure holding the information you need, e.g.

typedef struct _tagTHREAD_PARAMETER_BLOCK
{
 int nMyInt1;
 char acString1 [ 256];
 int nMyInt2;
 char acString2[ 256];
 /* whatever you need ... */
} THREAD_PARAMETER_BLOCK, *PTHREAD_PARAMETER_BLOCK;

THREAD_PARAMETER_BLOCK tpb;

tpb.nMyInt1 = 42;

strcpy ( tpb.acString1, "test");

_beginthread ( MyThread, 0, ( void*) tpb);

void MyThread ( void* pv)
{
PTHREAD_PARAMETER_BLOCK ptpb = (PTHREAD_PARAMETER_BLOCK) pv;
int n;

 n = ptpb->nMyInt1;

/* ... */
}


Feel free to ask if you need more information!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question