<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>X the Unknown &#187; Windows编程</title>
	<atom:link href="http://www.xinside.net/tag/windows-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xinside.net</link>
	<description>Becoming an ``X&#039;&#039; in an equation.</description>
	<lastBuildDate>Tue, 06 Sep 2011 02:51:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>WinMain-&gt;main</title>
		<link>http://www.xinside.net/2009/02/07/winmain-to-main/</link>
		<comments>http://www.xinside.net/2009/02/07/winmain-to-main/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 12:59:15 +0000</pubDate>
		<dc:creator>X</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[Windows编程]]></category>

		<guid isPermaLink="false">http://www.xinside.net/?p=402</guid>
		<description><![CDATA[我想基本上每一个有Windows GUI编程经历的人都知道：对于一般的Win32 Console程序（就是一般的C/C++程序），程序的入口是main；对于一般的 Win32 GUI程序，程序的入口是WinMain。 对于main不一定就是一般C/C++程序的入口，看过不少相关的评论也算是知道的，main仅仅是一个标准规定的符号；对于GUI程序，如果用前面的情况类比，那么WinMain也不一定就是入口。只不过……你想象过用main来换掉WinMain吗？ 我是没有想过的，虽然这说的通，main怎么说都是标准的定义，WinMain不过是微软自己定的，但main没有WinMain定义的参数。再说进入WinMain之前的“初始化”也可能和进入main之前的不一样。 不过经过今晚，尽管无法断言初始化的工作是否一样（十有八九不一样），但是用main来代替WinMain，应该是行得通的。WinMain的四个参数中，第二个一般用不上，第三个和main的第二个差不多，第四个是可以显式指定的，剩下的第一个，可以通过GetModuleHandle(NULL)来获得，结果： int main &#40;&#41; &#123; &#160; HINSTANCE hInst = GetModuleHandle&#40;NULL&#41;; &#160; /* &#160; ... &#160; */ &#160; &#125; 然后编译，链接，记得链接上GUI程序所必需的核心库。然后运行，得到的结果和用WinMain写的看上去是一样的，除了多了个黑色底的console window。]]></description>
			<content:encoded><![CDATA[<p>我想基本上每一个有Windows GUI编程经历的人都知道：对于一般的Win32 Console程序（就是一般的C/C++程序），程序的入口是main；对于一般的 Win32 GUI程序，程序的入口是WinMain。</p>
<p>对于main不一定就是一般C/C++程序的入口，看过不少相关的评论也算是知道的，main仅仅是一个标准规定的符号；对于GUI程序，如果用前面的情况类比，那么WinMain也不一定就是入口。只不过……你想象过用main来换掉WinMain吗？</p>
<p>我是没有想过的，虽然这说的通，main怎么说都是标准的定义，WinMain不过是微软自己定的，但main没有WinMain定义的参数。再说进入WinMain之前的“初始化”也可能和进入main之前的不一样。</p>
<p>不过经过今晚，尽管无法断言初始化的工作是否一样（十有八九不一样），但是用main来代替WinMain，应该是行得通的。WinMain的四个参数中，第二个一般用不上，第三个和main的第二个差不多，第四个是可以显式指定的，剩下的第一个，可以通过GetModuleHandle(NULL)来获得，结果：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> main <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
HINSTANCE hInst <span style="color: #000080;">=</span> GetModuleHandle<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*
&nbsp;
...
&nbsp;
*/</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>然后编译，链接，记得链接上GUI程序所必需的核心库。然后运行，得到的结果和用WinMain写的看上去是一样的，除了多了个黑色底的console window。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xinside.net/2009/02/07/winmain-to-main/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

