{"id":8630,"date":"2012-02-06T00:14:54","date_gmt":"2012-02-05T16:14:54","guid":{"rendered":"http:\/\/bohu.net\/blog\/?p=8630"},"modified":"2012-02-06T00:14:54","modified_gmt":"2012-02-05T16:14:54","slug":"%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e4%b8%80%e4%b8%aa%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e6%98%af-%e6%8e%a7%e5%88%b6%e5%8f%b0console%e7%a8%8b%e5%ba%8f%e8%bf%98%e6%98%af-gui-%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/www.bohu.net\/blog\/8630\/","title":{"rendered":"\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u662f \u63a7\u5236\u53f0(console)\u7a0b\u5e8f\u8fd8\u662f GUI \u7a0b\u5e8f"},"content":{"rendered":"<p><small>2012\u5e742\u67086\u65e5<\/small>\u4f5c\u8005:enet<\/p>\n<p>&nbsp;<\/p>\n<div>Article ID: 90493 \u2013 Last Review: November 21, 2006 \u2013 Revision: 3.2<\/div>\n<h4>HOWTO: How To Determine Whether an Application is Console or GUI<\/h4>\n<div><a href=\"http:\/\/my.unix-center.net\/%7Eenet\/feed#appliesto\" target=\"_blank\">View products that this article applies to.<\/a><\/div>\n<div>This article was previously published under Q90493<\/div>\n<div>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013<\/div>\n<p>\u82e5\u8981\u786e\u5b9a\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u4e3a\u63a7\u5236\u53f0\u6216 GUI\uff0c\u60a8\u5fc5\u987b\u5206\u6790\u8be5 EXEheader\u3002\u6807\u5934\u5305\u542b\u4e00\u4e2a\u79f0\u4e3a\u5b50\u7cfb\u7edf\u7684\u5b57\u6bb5\u3002\u6b64\u5b57\u6bb5\u786e\u5b9a\u662f\u8981\u5728\u5176\u4e0b\u8fd0\u884c\u7684\u5e94\u7528\u7a0b\u5e8f\u5b50\u7cfb\u7edf\u548c\u5b83\u9700\u8981\u7684\u63a5\u53e3\u7684\u7c7b\u578b\u3002\u503c\u7ec4\u6210:<\/p>\n<p>IMAGE_SUBSYSTEM_NATIVE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<br \/>\nIMAGE_SUBSYSTEM_WINDOWS_GUI\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2<br \/>\nIMAGE_SUBSYSTEM_WINDOWS_CUI\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3<br \/>\nIMAGE_SUBSYSTEM_OS2_CUI\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5<br \/>\nIMAGE_SUBSYSTEM_POSIX_CUI\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 7<br \/>\nIMAGE_SUBSYSTEM_NATIVE_WINDOWS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8<br \/>\nIMAGE_SUBSYSTEM_WINDOWS_CE_GUI\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 9<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<pre class=\"brush:cpp\">#include &lt;windows.h&gt;\n#include &lt;winnt.h&gt;\n\nVOID  main(int, char **);\nDWORD AbsoluteSeek(HANDLE, DWORD);\nVOID  ReadBytes(HANDLE, LPVOID, DWORD);\nVOID  WriteBytes(HANDLE, LPVOID, DWORD);\nVOID  CopySection(HANDLE, HANDLE, DWORD);\n\n#define XFER_BUFFER_SIZE 2048\n\nVOID\nmain(int argc, char *argv[])\n{\nHANDLE hImage;\n\nDWORD  bytes;\nDWORD  iSection;\nDWORD  SectionOffset;\nDWORD  CoffHeaderOffset;\nDWORD  MoreDosHeader[16];\n\nULONG  ntSignature;\n\nIMAGE_DOS_HEADER      image_dos_header;\nIMAGE_FILE_HEADER     image_file_header;\nIMAGE_OPTIONAL_HEADER image_optional_header;\nIMAGE_SECTION_HEADER  image_section_header;\n\nif (argc != 2)\n{\nprintf(\"USAGE: %s program_file_name\\n\", argv[1]);\nexit(1);\n}\n\n\/*\n*  Open the reference file.\n*\/\nhImage = CreateFile(argv[1],\nGENERIC_READ,\nFILE_SHARE_READ,\nNULL,\nOPEN_EXISTING,\nFILE_ATTRIBUTE_NORMAL,\nNULL);\n\nif (INVALID_HANDLE_VALUE == hImage)\n{\nprintf(\"Could not open %s, error %lu\\n\", argv[1], GetLastError());\nexit(1);\n}\n\n\/*\n*  Read the MS-DOS image header.\n*\/\nReadBytes(hImage,\n&amp;image_dos_header,\nsizeof(IMAGE_DOS_HEADER));\n\nif (IMAGE_DOS_SIGNATURE != image_dos_header.e_magic)\n{\nprintf(\"Sorry, I do not understand this file.\\n\");\nexit(1);\n}\n\n\/*\n*  Read more MS-DOS header.       *\/\nReadBytes(hImage,\nMoreDosHeader,\nsizeof(MoreDosHeader));\n\n\/*\n*  Get actual COFF header.\n*\/\nCoffHeaderOffset = AbsoluteSeek(hImage, image_dos_header.e_lfanew) +\nsizeof(ULONG);\n\nReadBytes (hImage, &amp;ntSignature, sizeof(ULONG));\n\nif (IMAGE_NT_SIGNATURE != ntSignature)\n{\nprintf(\"Missing NT signature. Unknown file type.\\n\");\nexit(1);\n}\n\nSectionOffset = CoffHeaderOffset + IMAGE_SIZEOF_FILE_HEADER +\nIMAGE_SIZEOF_NT_OPTIONAL_HEADER;\n\nReadBytes(hImage,\n&amp;image_file_header,\nIMAGE_SIZEOF_FILE_HEADER);\n\n\/*\n*  Read optional header.\n*\/\nReadBytes(hImage,\n&amp;image_optional_header,\nIMAGE_SIZEOF_NT_OPTIONAL_HEADER);\n\nswitch (image_optional_header.Subsystem)\n{\ncase IMAGE_SUBSYSTEM_UNKNOWN:\nprintf(\"Type is unknown.\\n\");\nbreak;\n\ncase IMAGE_SUBSYSTEM_NATIVE:\nprintf(\"Type is native.\\n\");\nbreak;\n\ncase IMAGE_SUBSYSTEM_WINDOWS_GUI:\nprintf(\"Type is Windows GUI.\\n\");\nbreak;\n\ncase IMAGE_SUBSYSTEM_WINDOWS_CUI:\nprintf(\"Type is Windows CUI.\\n\");\nbreak;\n\ncase IMAGE_SUBSYSTEM_OS2_CUI:\nprintf(\"Type is OS\/2 CUI.\\n\");\nbreak;\n\ncase IMAGE_SUBSYSTEM_POSIX_CUI:\nprintf(\"Type is POSIX CUI.\\n\");\nbreak;\n\ncase IMAGE_SUBSYSTEM_NATIVE_WINDOWS:\nprintf(\"Type is native Win9x driver.\\n\");\nbreak;\n\ncase IMAGE_SUBSYSTEM_WINDOWS_CE_GUI:\nprintf(\"Type is Windows CE.\\n\");\nbreak;\n\ndefault:\nprintf(\"Unknown type %u.\\n\", image_optional_header.Subsystem);\nbreak;\n}\n}\n\nDWORD\nAbsoluteSeek(HANDLE hFile,\nDWORD  offset)\n{\nDWORD newOffset;\n\nif ((newOffset = SetFilePointer(hFile,\noffset,\nNULL,\nFILE_BEGIN)) == 0xFFFFFFFF)\n{\nprintf(\"SetFilePointer failed, error %lu.\\n\", GetLastError());\nexit(1);\n}\n\nreturn newOffset;\n}\n\nVOID\nReadBytes(HANDLE hFile,\nLPVOID buffer,\nDWORD  size)\n{\nDWORD bytes;\n\nif (!ReadFile(hFile,\nbuffer,\nsize,\n&amp;bytes,\nNULL))\n{\nprintf(\"ReadFile failed, error %lu.\\n\", GetLastError());\nexit(1);\n}\nelse if (size != bytes)\n{\nprintf(\"Read the wrong number of bytes, expected %lu, got %lu.\\n\",\nsize, bytes);\nexit(1);\n}\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2012\u5e742\u67086\u65e5\u4f5c\u8005:enet &nbsp; Article ID: 90493 \u2013 Last Review &hellip; <a href=\"https:\/\/www.bohu.net\/blog\/8630\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u662f \u63a7\u5236\u53f0(console)\u7a0b\u5e8f\u8fd8\u662f GUI \u7a0b\u5e8f\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,40,12,26,27],"tags":[114,137,179,180,186,526,575],"class_list":["post-8630","post","type-post","status-publish","format-standard","hentry","category-c-2","category-unix-center-net","category-windows","category-26","category-27","tag-console","tag-dword","tag-gui","tag-handle","tag-howto","tag-526","tag-575"],"_links":{"self":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/8630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/comments?post=8630"}],"version-history":[{"count":0,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/8630\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/media?parent=8630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/categories?post=8630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/tags?post=8630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}