WinMain 在 main 之前未调用(C/C++ 程序入口点问题)

发布于 2024-08-29 01:16:03 字数 420 浏览 13 评论 0原文

我的印象是这段代码

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七秒鱼° 2024-09-05 01:16:03

调用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.

挽清梦 2024-09-05 01:16:03

编译器将根据您将编译输出定位到 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.

一城柳絮吹成雪 2024-09-05 01:16:03

刚刚发现这个工作,感觉有点愚蠢。

#define main USER_Main

这样一来,main 就不再是程序的入口点,同时仍然向用户隐藏了任何事情都被搞乱的事实。

Just found this work around and kind of feel dumb.

#define main USER_Main

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文