| View previous topic :: View next topic |
| Author |
Message |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sun Mar 22, 2009 3:38 pm Post subject: [?] Passing multple parameters with CreateThread() |
|
|
| How can I do this?
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Mar 22, 2009 3:45 pm Post subject: |
|
|
| Allocate a piece of memory for the stack, Write all your parameters onto that and set it as the stack parameter? I haven't tried so Im just guessing.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Mar 22, 2009 4:20 pm Post subject: |
|
|
| make a structure or an array of the info you want to pass. then pass a pointer to that structure/array
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sun Mar 22, 2009 10:46 pm Post subject: |
|
|
| Slugsnack wrote: | | make a structure or an array of the info you want to pass. then pass a pointer to that structure/array |
Exactly.
| Code: |
typedef struct _THREAD_PARAMETER {
int nFirstParam;
char *szSecondParam;
char *szThirdParam;
double FourthParam[100];
} THREAD_PARAMETER, *LPTHREAD_PARAMETER;
void ThreadFunction( LPVOID lpParam );
void StartThread( int *tID, int nFirstParam, char *szSecondParam, char *szThirdParam, double FourthParam[ ] ) {
THREAD_PARAMETER ThreadParam;
ThreadParam.nFirstParam = nFirstParam;
strcpy( ThreadParam.szSecondParam, szSecondParam );
strcpy( ThreadParam.szThirdParam, szThirdParam );
memcpy( ThreadParam.FourthParam, FourthParam, sizeof( double ) * 100 );
CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE )ThreadFunction, &ThreadParam, 0, tID );
}
void ThreadFunction( LPVOID lpParam ) {
THREAD_PARAMETER ThreadParam = *( LPTHREAD_PARAM )lpParam;
std::cout << ThreadParam.nFirstParam << std::endl;
std::cout << ThreadParam.szSecondParam << std::endl;
std::cout << ThreadParam.szThirdParam << std::endl;
for( int i = 0; i < 100; i++ )
std::cout << ThreadParam.FourthParam[ i ] << std::endl;
}
|
_________________
|
|
| Back to top |
|
 |
|