アットウィキロゴ

C言語 外部アプリケーション起動

  1. #define N 10000
  2.  
  3. unsigned __stdcall child_thread(LPVOID param);
  4.  
  5. int main(){
  6.  
  7. int flag;
  8. HANDLE hthread;
  9. unsigned int threadId;
  10.  
  11. flag = 0;
  12. hthread = (HANDLE)_beginthreadex(NULL, 0, child_thread, (void *)&flag, 0, &threadId);
  13.  
  14. WaitForSingleObject(hthread, INFINITE);
  15.  
  16. return 0;
  17. }
  18.  
  19. unsigned __stdcall child_thread(void *param){
  20.  
  21. // TODO: この位置にコントロール通知ハンドラ用のコードを追加してください
  22. int ret_code;
  23. DWORD lpExitCode;
  24. PROCESS_INFORMATION pro_id;
  25. STARTUPINFO str_inf;
  26.  
  27. //-------------------------
  28. // pro_id構造体初期化
  29. ZeroMemory( &pro_id , sizeof(PROCESS_INFORMATION));
  30.  
  31. //-------------------------
  32. // str_inf構造体初期化
  33. ZeroMemory( &str_inf , sizeof(STARTUPINFO));
  34. str_inf.cb = sizeof(STARTUPINFO);
  35. str_inf.dwFlags = STARTF_USESHOWWINDOW;
  36. str_inf.wShowWindow = SW_SHOWNORMAL;
  37.  
  38. //-------------------------
  39. // 外部プロセスの実行
  40. ret_code = CreateProcess( L"C:\\SUPER_PI\\SUPER_PI.exe", NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &str_inf, &pro_id);
  41.  
  42. //--------------------------
  43. // プロセスの終了待ちループ
  44. lpExitCode = STILL_ACTIVE;
  45. while (lpExitCode == STILL_ACTIVE ) {
  46. // 終了コードを取得
  47. GetExitCodeProcess( pro_id.hProcess , &lpExitCode ) ;
  48. }
  49. CloseHandle(pro_id.hProcess);
  50.  
  51. return 0;
  52. }
  53.  
累計のアクセス数: -
今日のアクセス数: -
昨日のアクセス数 -
最終更新:2011年07月25日 08:32