mainWCRTStartup 与 wmain

来源:互联网 发布:网络区域推广方法 编辑:程序博客网 时间:2024/06/05 09:35

The C Run-Time Libraries for Windows CE (CRT) provide many useful functions that can make programming much easier.

The CRT resides in two core libraries, COREDLL.DLL and CORELIBC.LIB.

  • You can link to the portion of the CRT in COREDLL.DLL by linking with COREDLL.LIB, the import library for COREDLL.DLL.
  • CORELIBC.LIB contains the CRT startup routines. In addition, it contains other CRT routines that you must link to statically, primarily to ensure optimum performance.

When you link your image, you explicitly or implicitly specify an entry point that the operating system will call into after loading the image.

For a DLL, the default entry point is _DllMainCRTStartup.

For an EXE, the default entry is wWinMainCRTStartup, the Unicode entry point for an EXE that defines the wWinMain function, orWinMainCRTStartup otherwise.

You can rely on the default entry point that the linker chooses, but the best practice is usually to override the default choice. Instead, specify an entry point with the /ENTRY linker option.

Windows CE supports the following CRT entry points:

  • mainACRTStartup for applications that define the main function
  • mainWCRTStartup for applications that define the wmain function
  • WinMainCRTStartup for applications that define the WinMain function
  • wWinMainCRTStartup for applications that define the wWinMain function
  • _DllMainCRTStartup for DLLs

For more information, see the linker topic /ENTRY (Entry-Point Symbol).

Note   If you want to use mainACRTStartup or mainWCRTStartup, you must explicitly state that when you specify the /ENTRYoption.

_tmain:
1. main是所有C或C++的程序执行的起点,_tmain是main为了支持unicode所使用的main的别名。
2. _tmain需要一个返回值,而main默认为void。
3. _tmain的定义在<tchar.h>可以找到,如#define _tmain main,所以要加 #include <tchar.h> 才能用。
4. _tmain()是个宏,如果定义了UNICODE,则他是wmain(),否则他是main()。
5. _tmain这个符号多见于VC++创建的控制台工程中,这个是为了保证移植unicode而加入的。
6. 一般_t、_T、T()这些东西都是宏都和unicode有关系。
7. 对于使用非unicode字符集的工程来说,实际上_tmain和main没有差别。
8. 因此_tmain编译后后仍为main,所以都可以执行。
9. main()是WINDOWS的控制台程序(32BIT)或DOS程序(16BIT)。
10.WinMain()是WINDOWS的GUI程序。
11.另外,wmain也是main的另一个别名,是为了支持二个字节的Unicode语言环境。
  -----------------------
  int main( int argc, char *argv[ ], char *envp[ ])
  wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )
  int _tmain(int argc, _TCHAR* argv[ ])


参考文章:

http://msdn.microsoft.com/en-us/library/ms859584.aspx

http://blog.sina.com.cn/s/blog_48a45b950100ykwl.html



原创粉丝点击