我怎么能不写WinMain函数使用一个Windows应用程序? [英] How can I write a Windows application without using WinMain?
问题描述
写在C / C的Windows GUI应用程序++有'WinMain函数为切入点,(而不是'主')。我对此的理解是,编译器生成一个'主'功能的C运行时调用。此'主'函数设置的图形用户界面所需的环境,并调用到'WinMain函数(指定实例句柄等)。
Windows GUI applications written in C/C++ have 'WinMain' as an entry point (rather than 'main'). My understanding of this is that the compiler generates a 'main' function to be called by the C Runtime. This 'main' function sets up the necessary environment for the GUI and calls into 'WinMain' (specifying the instance handles etc.).
总之,我相信控制台和GUI应用程序启动时通过以下方式有所不同:
In short, I believe console and GUI application startup to differ in the following way:
控制台应用程序:
C运行时 - >'主'功能(手工codeD)
Console application: C Runtime --> 'main' function (hand-coded)
GUI应用程序:
C运行时 - >'主'功能(编译器生成) - >的WinMain'功能(手工codeD)
GUI application: C Runtime --> 'main' function (compiler-generated) --> 'WinMain' function (hand-coded)
我想这两个验证这种理解和找出我怎么能手工code一个Windows图形用户界面只是一个'主'功能(即,而不必编写'WinMain函数')
I would like to both validate this understanding and find out how I can hand-code a Windows GUI with just a 'main' function (i.e. without having to write 'WinMain').
推荐答案
您有一个不正确的认识。主WinMain函数之间的区别,除了一些differet初始化code,是传递给它的参数。
You have an incorrect understanding. The difference between main and WinMain, apart from some differet initialization code, is the parameters passed to it.
主要是这样的:
int main(int argc, char* argv[]);
虽然WinMain中是这样的:
While WinMain looks like this:
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
);
事情已经设置这些参数,并拨打电话,这是启动code。当您编译和链接程序,链接器的参数之一就是切入点,这将是,取决于控制台或GUI应用程序,启动code不同的一点。
Something has to setup those parameters and make the call, and that's the startup code. When you compile and link a program, one of the linker parameters is the entry point, and that will be, depending on a console or GUI app, a different bit of startup code.
您当然可以写你自己的启动code,只要进入你的Visual C ++源代码目录,你可以找到启动code,这就是所谓的crt0.c,它是在VC \\ CRT \\ src目录。
You can certainly write your own startup code, just go into your visual c++ source directory and you can find the startup code, it's called crt0.c and it's in the VC\crt\src directory.
这篇关于我怎么能不写WinMain函数使用一个Windows应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!