一個noconsole程式

來源:互聯網
上載者:User

標籤:

貌似是一個外國人寫的,作用應該是讓控制台的程式啟動並執行時候不會彈出那個控制台黑框。想用來讓它不顯示 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程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.