zoukankan      html  css  js  c++  java
  • 一个noconsole程序

    貌似是一个外国人写的,作用应该是让控制台的程序运行的时候不会弹出那个控制台黑框。想用来让它不显示 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 #endif
    10 
    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>...]
    ", 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.
    ", (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中会出错。

  • 相关阅读:
    0.计算机相关
    面试笔试大概会出现的问题其二
    uboot传递启动参数给内核
    移植uboot之裁剪和修改参数
    uboot移植之支持板子nand启动
    uboot移植之建立新板、初始化时钟/SDRAM/UART
    uboot移植之重定位
    uboot移植之重定位之前的启动过程
    uboot移植之初步编译
    输入子系统分析
  • 原文地址:https://www.cnblogs.com/vanwoos/p/4855990.html
Copyright © 2011-2022 走看看