Solved

Create an arglist for _beginthread function

Posted on 2000-03-03
1
497 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 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

Independent Software Vendors: 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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements 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.
Suggested Courses

752 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