| | |
CreateThread & CreateRemoteThread
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
now create an instance of the thread in your program
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)
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.
C++ Syntax (Toggle Plain Text)
DWORD WINAPI ThreadProc( LPVOID lpParameter) { // blabla return 0; }
now create an instance of the thread in your program
C++ Syntax (Toggle Plain Text)
DWORD dwThreadID; HANDLE hThread = CreateThread(0,0,ThreadProc,0,0,&dwThreadID);
C++ Syntax (Toggle Plain Text)
DWORD dwThreadID; HANDLE hThread = CreateThread(0,0,ThreadProc,this,0,&dwThreadID);
•
•
Join Date: Dec 2005
Posts: 14
Reputation:
Solved Threads: 0
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:
I've seen examples of this being done but not with an array type structure so i'm stuck.
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:
C++ Syntax (Toggle Plain Text)
struct Blah { char test[512]; char testnext[512]; } TestStruct[5]; DWORD WINAPI testproc(LPVOID param) { //how would i grab the paramater here? } int main(void) { memset(TestStruct[0].test,0,sizeof(TestStruct[0].test)); strncpy(TestStruct[0].test,"blah..",sizeof(TestStruct[0].test)-1); DWORD id; HANDLE ThreadHandle; //i know this is definately wrong, i just added it so you can see what i'm trying to pass to the thread function ThreadHandle = CreateThread(0, 0, &testproc, (LPVOID)&TestStruct[0], 0, &id); return 0; }
![]() |
Similar Threads
- Web Design & Development Company Hiring (Web Development Job Offers)
- Probelm in JSP with (& and # symbols) (JSP)
- Connected ATX and AT PSU (Technical) (Motherboards, CPUs and RAM)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: #include custom files
- Next Thread: please fix the error
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






