flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > How to remove show of the console window in the console app?

Author
Thread Post new topic Reply to topic
addhaloka



Joined: 23 Oct 2013
Posts: 9
How to remove show of the console window in the console app?
Hi,

I made a simple programm for Total Commander which creates folders with names as format YYYY-MM-DD_HH-MM-SS.
I noticed when make it as 'PE CONSOLE', it works a little faster, but in this case I do not like the flashing console window. Can hide the window by configuring in the Total Commander, but I would like to remove it directly in the program (if it is, of course, possible).

Best regards, addhaloka.
Post 19 Jul 2017, 16:02
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 556
There is no reason that a console app should be faster than one without. After all, the "console" thing is part of the PE format and is a single thing you have to change -- it is definitely not part of your "code". You can even change it manually with a Hex Editor.

Now of course it could be slower if your runtime adds a lot of stupid bloat and junk to the non-console version. Do you control the entry point of your application? You should. I don't have more info about it, so providing more info would help. Is it written in asm or C/C++ or something else?

You can still use e.g. C standard library (even from asm) without actually pulling that bloat into your executable, just link msvcrt.dll or whatever else you need and let it handle the symbol lookup. (note: if you use C compiler you'll have to pass some options, for GCC it is -nostdlib, to get full control over the entry point; main is NOT the entry point, it happens after a lot of bloat)

But yes, I need more info first on how you build your app Wink


Oh, to add, if you want to "remove" the console window you need to turn it into a non-console application. This does not require changing your code but it could break. You need to change a byte only. I'm not sure if it will work, given the runtime initialization (if any?), you need to change the Subsystem field of this: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680339%28v=vs.85%29.aspx (look online about PE format if you really want to do this "hack"; change it to 2 or IMAGE_SUBSYSTEM_WINDOWS_GUI, it should be set to 3 currently since it's console)
Post 19 Jul 2017, 20:42
View user's profile Send private message Reply with quote
addhaloka



Joined: 23 Oct 2013
Posts: 9
Furs
Naturally, I made it in FASM. Smile It is enough replace PE GUI to PE CONSOLE, program for some reason starts to work a little faster. Confused
Source code:

Code:
format PE GUI 5.0       ; if replace 'GUI' to 'CONSOLE' its really works faster
entry start

include 'win32w.inc'

section '.text' code readable executable
align 10h
data import
        library kernel32,'KERNEL32.DLL',\
                        user32,'USER32.DLL'
        include 'api/kernel32.inc'
        include 'api/user32.inc'
end data
align 10h
fmt             du      '%4.4u-%2.2u-%2.2u_%2.2u-%2.2u-%2.2u',0
align 10h

proc getTargetDir
        push    esi edi
        invoke  GetCurrentDirectory,MAX_PATH*2,targetdir
        mov             esi,targetdir
        mov             edi,targetdir
        @@:
        lodsw
        stosw
        test    ax,ax
        jne             @B
        sub             esi,2
        mov             word[esi],5Ch
        add             esi,2
        mov             word[esi],0
        pop             edi esi
        ret
endp

start:
        invoke  GetLocalTime,systemtime
        movsx   eax,[systemtime.wYear]
        movsx   ecx,[systemtime.wMonth]
        movsx   edx,[systemtime.wDay]
        movsx   ebx,[systemtime.wHour]
        movsx   esi,[systemtime.wMinute]
        movsx   edi,[systemtime.wSecond]
        cinvoke wsprintf,dirname,fmt,eax,ecx,edx,ebx,esi,edi
        call    getTargetDir
        invoke  lstrcat,targetdir,dirname
        invoke  CreateDirectory,targetdir,0
        invoke  ExitProcess,0

section '.data' readable writeable
dirname         du      20 dup(?)
targetdir       du      MAX_PATH dup(?)
systemtime      SYSTEMTIME

Post 19 Jul 2017, 23:33
View user's profile Send private message Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 111
Location: i@grompe.org.ru
Programs that differ only by Console/GUI bit are equally fast for me.

Perhaps you should check for resident software you have installed that injects its own nonsense to all starting GUI programs.
Post 20 Jul 2017, 07:24
View user's profile Send private message Visit poster's website Reply with quote
addhaloka



Joined: 23 Oct 2013
Posts: 9

Grom PE wrote:
Perhaps you should check for resident software you have installed that injects its own nonsense to all starting GUI programs.


Hardly - it was tested on different PCs/OS (XP SP3 x86, Win 7 x86/x64, Win 8.1 x64) - everywhere the same behavior. Also for a long time already I do not use antiviruses, HIPS, etc., i.e. software that can cause similar effects.
Post 20 Jul 2017, 14:03
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 556
How do you judge how fast it is?

Total Commander might not redraw its window immediately after you launch the app with GUI; but it will after the console since OS forces a refresh (because there was a window in the way, you know?). So that's why it could feel faster. In this sense, both are instant except one is just updated slower on your screen.

I know with Wine (on Linux) Total Commander doesn't redraw instantly many times, but it could be a wine thing of course.

Of course if you have another means to judge how fast it is other than the screen itself, then this isn't the issue. Can't say it happens here, sorry, so I'm stumped if so. Confused
Post 20 Jul 2017, 14:15
View user's profile Send private message Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 111
Location: i@grompe.org.ru
Yeah, check again with ptime: http://www.pc-tools.net/win32/ptime/
Post 20 Jul 2017, 21:19
View user's profile Send private message Visit poster's website Reply with quote
addhaloka



Joined: 23 Oct 2013
Posts: 9
In vain I, probably, addressed this question - it was necessary to look first in google.
That there was no window it is necessary compile as GUI and nothing else.
There are at least two (FreeConsole, or GetConsoleWindow > ShowWindow,eax,SW_HIDE) ways to hide the window in the console app, but they are useless, since the program is already completing the task and ends, while the window is still blinking. Very Happy
Thanks to everyone and sorry for disturbing.
Post 21 Jul 2017, 04:59
View user's profile Send private message Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 111
Location: i@grompe.org.ru
It's a bad idea to hide the console window — it may not be yours. What if I run your program from a console program?
Post 21 Jul 2017, 06:42
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.