Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What function actually calls WinMain

Tags:

c

winapi

How is WinMain() actually called? I remember a function used by pro-hackers that started with (something) that looked like __startupWinMain().

The problem is, I have a Win32 EXE(compiled with /SUBSYSTEM:WINDOWS) but gets arguments from command-line. If the command line is incorrect, the process should print a help message to the console.

How can I manually deallocate(or FreeConsole()) from an exe with /SUBSYSTEM:WINDOWS linker option?

like image 932
Aniket Inge Avatar asked Sep 07 '25 04:09

Aniket Inge


1 Answers

As the very first act of your program, check the parameters. If they are fine, continue as normal.

Otherwise call AttachConsole passing ATTACH_PARENT_PROCESS. If that succeeds, then you can print your error to stdout and quit. If it doesn't, then you'll have to show the error in a message box.

like image 161
David Heffernan Avatar answered Sep 09 '25 01:09

David Heffernan