Solved

Create an arglist for _beginthread function

Posted on 2000-03-03
1
491 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
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 50 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

685 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