进程与线程的创建
程序员文章站
2022-08-30 23:38:15
// TmpThread.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #include using namespace std; //线程函数 DWORD WINAPI StartAddress(LPVOID lpParameter) {... ......
// tmpthread.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> #include <iostream> using namespace std; //线程函数 dword winapi startaddress(lpvoid lpparameter) { cout << "\ni am a very simple thread!" <<endl; return 0; } int main() { //创建进程 startupinfo startupinfo = { 0 }; process_information processinfo = { 0 }; bool bsuccess = createprocess(l"..\\debug\\tmpprocess.exe", null, null, null, false, null, null, null, &startupinfo, &processinfo); if (bsuccess) { cout << "\nprocess running successed!" << endl; } else { cout << "\nprocess running faild!" << endl; } //创建线程 handle hthread = createthread(null, 0, /*(lpthread_start_routine)*/startaddress, null, null, null); waitforsingleobject(hthread,infinite);//等待线程执行完在执行后续代码 closehandle(hthread); system("pause"); return 0; }
下一篇: 领略美国五大最高摩天轮的别样风光