winapi console trouble

Started by
6 comments, last by SiCrane 10 years, 6 months ago

Some time ago I was trying move my winapi framework code to external static lib (you could call it flib) so I could use it as an api which i could run from simple c environment like

 
void init_firs_framework();
void draw_frame_here();
 
 
void draw_frame_here()
{
  //....
}
 
void main()
{
  init_firs_framework();
}
 

but there appear some trouble. I am using winapi to setup my window

and want to use my flib as an only api avaliable to my main program -

the trouble is that compiling 'console' program such as my main program

here makes an ugle blue console to appear, I do not need such sh*t here,

I also do not want to use WinMain instead of main() in my main program

I just need to write c main program which will rely on my own flib api

not involving both c console on WinMain() environment - I was searching

abit but not found how to compile windows program which will not

involve making console or winapi but come kind of raw compilation for

my own lib.

Advertisement

All programs executed in the Windows console subsystem automatically have a console window created. That's simply part of how Windows works. However, depending on your compiler and linker you may be able to specify main() as the entry point for a program that uses the Windows subsystem. How you go about it would depend on your tool chain.

All programs executed in the Windows console subsystem automatically have a console window created. That's simply part of how Windows works. However, depending on your compiler and linker you may be able to specify main() as the entry point for a program that uses the Windows subsystem. How you go about it would depend on your tool chain.

As i said I do not want to use window subsystem and i do not want to use console subsystem I just want to wrote 'Raw' c code program, which will be linking staticaly to my own flib.obj (which is using winapi)

And this is stupid problem as i said, i run my program sudenly totally unnecessary console do apear (And i cannot switch tu windows subsystem becouse i do not need it to, I just need pure main and code linked to my own framework)


As i said I do not want to use window subsystem

Actually what you said is that you don't want to use WinMain(). Entry point is not synonymous with subsystem, and just because you use the Windows subsystem doesn't mean you need to use WinMain() as your entry point unless your tool chain requires it. Some tool chains will allow you to use main() as your entry point even if you use the Windows subsystem. Again, how you would go about that would depend on your tool chain. But yes, you do need to switch to a different subsystem if you don't want the console window to show up. The operating system creates the console window for any application run in the console subsystem. There's nothing application code can do to suppress that console window creation if you run in the console subsystem. And you have to run in one of the subsystems. Subsystem is specified as part of the PE executable header. If you don't have a valid subsystem entry then the OS won't know how to launch your program.


As i said I do not want to use window subsystem

Actually what you said is that you don't want to use WinMain(). Entry point is not synonymous with subsystem, and just because you use the Windows subsystem doesn't mean you need to use WinMain() as your entry point unless your tool chain requires it. Some tool chains will allow you to use main() as your entry point even if you use the Windows subsystem. Again, how you would go about that would depend on your tool chain. But yes, you do need to switch to a different subsystem if you don't want the console window to show up. The operating system creates the console window for any application run in the console subsystem. There's nothing application code can do to suppress that console window creation if you run in the console subsystem. And you have to run in one of the subsystems. Subsystem is specified as part of the PE executable header. If you don't have a valid subsystem entry then the OS won't know how to launch your program.

I tell you why I say I do not want a window subsystem - I got my own library flib.obj where I got my own api for making small 2d games it calls winapi internally.

I want to set up some easy environment for making games

in the form of c program using only my own libraray as an api

calls - no direct calls to winapi or any other thing just the simplicity






#include "flib.h"          // -> flib.obj
 
void main()
{
    // game here using only functions 
    // given to you by flib and nothing more
}

I do not want to force a user of flib to any efforts (setting subsystem to windows or something)

I would like give him a lib, make him fire the c compiler, include header in standard c environment (preferebly would like if it would work with many compilers) and go (als I do not need, f**ing console)

What you would do it? I got a trouble here - and i consider it as a some kind of 'system' bug that it is some trouble to make it this way

You can do what SDL does and have your library contain WinMain() and use a preprocessor definition in a header to #define main to something else that your WinMain() will call. SDL uses SDL_main. That will allow the user to use main() without manually setting the entry point. However, the user will still need to implicit or explicitly set the subsystem to Windows. For example, in MSVC by creating a new Windows application rather than console application. If the user creates a console application the application is going to get a console window and there's nothing you can do to prevent that.

You can do what SDL does and have your library contain WinMain() and use a preprocessor definition in a header to #define main to something else that your WinMain() will call. SDL uses SDL_main. That will allow the user to use main() without manually setting the entry point. However, the user will still need to implicit or explicitly set the subsystem to Windows. For example, in MSVC by creating a new Windows application rather than console application. If the user creates a console application the application is going to get a console window and there's nothing you can do to prevent that.

its sad i do not know what such windows subsystem code

do - but maybe i can assume that it do about nothing

This all winmain seem to me to be an bad choice (design bug) in the windows system - some man do it bad

the arguments that winmain carries should be IMo accesible

through some winapi call - to not breac clear c code program form :c

The arguments are available via API calls. The HINSTANCE for the module can be found via GetModuleHandle(NULL), the command line via GetCommandLine(), nCmdShow can be found via GetStartupInfo() and checking the STARTF_USESHOWWINDOW bit of dwFlags. hPrevInstance is always NULL on any of the 32 or 64 bit versions of Windows.

This topic is closed to new replies.

Advertisement