CreateThread & CreateRemoteThread

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2005
Posts: 14
Reputation: osean is an unknown quantity at this point 
Solved Threads: 0
osean osean is offline Offline
Newbie Poster

CreateThread & CreateRemoteThread

 
0
  #1
Dec 27th, 2005
Hi, can someone point me to a good tutorial on using the CreateThread and CreateRemoteThread API?

I've already read the MSDN documentation for both functions, i'm looking for a site that explains the use of both functions in more detail and provides alot of example code, thanks.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,388
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: CreateThread & CreateRemoteThread

 
0
  #2
Dec 27th, 2005
I don't know about CreateRemoteThread -- never used it.

you probably won't find any "tutorials" because there isn't that much to it. Most of the parameters are 0, unless you want more control over the thread.

First create the thread itself -- name it anything you want. If it is a member of c++ class it must be static method.
  1. DWORD WINAPI ThreadProc( LPVOID lpParameter)
  2. {
  3. // blabla
  4.  
  5. return 0;
  6. }

now create an instance of the thread in your program
  1. DWORD dwThreadID;
  2. HANDLE hThread = CreateThread(0,0,ThreadProc,0,0,&dwThreadID);
The parameter immediately following ThreadProc is a parameter you want to pass to the thread. So if you want to pass the this pointer (assuming c++ program)
  1. DWORD dwThreadID;
  2. HANDLE hThread = CreateThread(0,0,ThreadProc,this,0,&dwThreadID);
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 14
Reputation: osean is an unknown quantity at this point 
Solved Threads: 0
osean osean is offline Offline
Newbie Poster

Re: CreateThread & CreateRemoteThread

 
0
  #3
Dec 28th, 2005
Thanks for your reply,
the main reason why I posted was because i'm specifically having problems with what you mentioned in the last part of your post, passing a paramater to the thread (I thought if people could point me to a site with some examples I could see real examples of it in use and figure it out myself).

Basically, I have an array type structure and I need to pass the object (i think?) associated with it to the thread, like the example code below:
  1. struct Blah {
  2. char test[512];
  3. char testnext[512];
  4. } TestStruct[5];
  5.  
  6. DWORD WINAPI testproc(LPVOID param) {
  7. //how would i grab the paramater here?
  8. }
  9.  
  10. int main(void) {
  11. memset(TestStruct[0].test,0,sizeof(TestStruct[0].test));
  12. strncpy(TestStruct[0].test,"blah..",sizeof(TestStruct[0].test)-1);
  13. DWORD id;
  14. HANDLE ThreadHandle;
  15. //i know this is definately wrong, i just added it so you can see what i'm trying to pass to the thread function
  16. ThreadHandle = CreateThread(0, 0, &testproc, (LPVOID)&TestStruct[0], 0, &id);
  17. return 0;
  18. }
I've seen examples of this being done but not with an array type structure so i'm stuck.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 14
Reputation: osean is an unknown quantity at this point 
Solved Threads: 0
osean osean is offline Offline
Newbie Poster

Re: CreateThread & CreateRemoteThread

 
0
  #4
Dec 28th, 2005
nevermind.. i figured it out, thanks anyway.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC