문제

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.

도움이 되었습니까?

해결책 3

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.

다른 팁

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top