WinMain 在 main 之前未调用(C/C++ 程序入口点问题)
我的印象是这段代码
#include <windows.h>
#include <stdio.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
printf("WinMain\n");
return 0;
}
int main()
{
printf("main\n");
return 0;
}
会输出 WinMain,但当然没有任何东西能如你所期望的那样工作。
无论如何,有人可以告诉我如何让这个程序首先运行 WinMain (我确实有使用两者的理由)。我正在使用 mingw 运行 Windows 7,如果这有帮助的话。
I was under the impression that this code
#include <windows.h>
#include <stdio.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
printf("WinMain\n");
return 0;
}
int main()
{
printf("main\n");
return 0;
}
would output WinMain, but of course nothing ever works how you expects.
Anyways, could somebody please tell me how to get this program to run WinMain first (I do have a reason for using both). I'm running windows 7 with mingw if that helps anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
调用MinGw时,需要在命令行中输入
-mwindows
。查看此,作为使用 MinGW 进行 Windows 编程的简单介绍。另外:可执行文件中不能有两个入口点,因此您可能无法执行您想要执行的操作。
You need to put
-mwindows
on the command line when you call MinGw. Check this out as a gentle introduction to Windows programming with MinGW.Also: you cannot have two entry points in an executable, so you probably can not do what you want to do.
编译器将根据您将编译输出定位到 Windows 子系统还是控制台子系统来选择一个入口点或另一个入口点。
WinMain
用于前者,main
用于后者。The compiler will choose one entry point or the other based on whether you're targeting the compiled output to the Windows subsystem or the Console subsystem.
WinMain
for the former,main
for the latter.刚刚发现这个工作,感觉有点愚蠢。
这样一来,main 就不再是程序的入口点,同时仍然向用户隐藏了任何事情都被搞乱的事实。
Just found this work around and kind of feel dumb.
This then takes main out of line for being the programs entry point while still hiding the fact that anything was messed with from the user.