// 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; }