標籤:
貌似是一個外國人寫的,作用應該是讓控制台的程式啟動並執行時候不會彈出那個控制台黑框。想用來讓它不顯示 php-cgi.exe 運行後的視窗,可是效果不是預期的。
項目在 github 的位置:https://github.com/mtstickney/noconsole
項目源碼:
1 #include <windows.h> 2 #include <shellapi.h> 3 #include <stdio.h> 4 5 #ifdef UNICODE 6 #define MAIN wWinMain 7 #else 8 #define MAIN WinMain 9 #endif10 11 int WINAPI MAIN(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR pCmdLine, int nCmdShow)12 {13 int argnum = 1;14 STARTUPINFO si;15 PROCESS_INFORMATION pi;16 DWORD exit_code;17 18 ZeroMemory(&si, sizeof(si));19 si.cb = sizeof(si);20 si.dwFlags = STARTF_USESHOWWINDOW;21 si.wShowWindow = SW_HIDE;22 ZeroMemory(&pi, sizeof(pi));23 24 /* Note: argnum is not like argc... */25 if (argnum < 1) {26 fputs("Usage: noconsole <program> [<args>...]\n", stderr);27 ExitProcess(1);28 }29 30 /* Start the child process */31 if (!CreateProcess(NULL, pCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, /* Note that the previous should maybe be set to the cwd of the program being run */32 &si,33 &pi))34 {35 fprintf(stderr, "Error starting process, code %d.\n", (int)GetLastError());36 ExitProcess(1);37 }38 39 /* Wait for child exit */40 WaitForSingleObject(pi.hProcess, INFINITE);41 42 GetExitCodeProcess(pi.hProcess, &exit_code);43 44 /* Clean up the handles */45 CloseHandle(pi.hProcess);46 CloseHandle(pi.hThread);47 48 ExitProcess(exit_code);49 return 0;50 }
第35行是手動添加上的強制類型轉換,不然在我的64位win8中會出錯。
一個noconsole程式