Please support our C++ advertiser: Programming Forums
![]() |
•
•
Join Date: Oct 2007
Location: Guadalajara, Mexico
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Hi everyone,
this is my first post. I'll try to be concise.
It's been a while since I've worked with C++, since I usually work in Java. I'm writing a program that I want to have run in the background while the system (Windows XP) starts up. But I want it to be invisible, e.g., not have the DOS command window appear.
The program is in C++ (Borland C++ 3.1, old history!). Of course, it does not include any output to the screen, only works with files.
Thanks to anybody who can provide any insight!!
this is my first post. I'll try to be concise.
It's been a while since I've worked with C++, since I usually work in Java. I'm writing a program that I want to have run in the background while the system (Windows XP) starts up. But I want it to be invisible, e.g., not have the DOS command window appear.
The program is in C++ (Borland C++ 3.1, old history!). Of course, it does not include any output to the screen, only works with files.
Thanks to anybody who can provide any insight!!
Alejandro Ramírez Lovering
Java Developer
Java Developer
•
•
Join Date: Oct 2007
Location: Guadalajara, Mexico
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,884
Reputation:
Rep Power: 13
Solved Threads: 197
Windows executables have a flag in the header that causes that console window to appear or not.
Try changing
to
Notice that by compiling a Windows application your command line is now an array of wchar strings.
If that doesn't work, post back and I'll give you a little program to change the exe subsystem type manually.
Hope this helps.
Try changing
int main( int argc, char **argv )
to
#include <windows.h>
#include <shellapi.h>
int WndMain() {
int argc;
wchar_t **argv = CommandLineToArgvW( GetCommandLine(), &argc );If that doesn't work, post back and I'll give you a little program to change the exe subsystem type manually.
Hope this helps.
> The program is in C++ (Borland C++ 3.1, old history!).
Then you're stuck, because all you can create are DOS programs.
If you want something smarter, you need to create a proper win32 service, and for that you'll need a compiler more in tune to the operating system you're using.
Sometimes backward compatibility is nice, but some people cling to it like some "security blanket".
Then you're stuck, because all you can create are DOS programs.
If you want something smarter, you need to create a proper win32 service, and for that you'll need a compiler more in tune to the operating system you're using.
Sometimes backward compatibility is nice, but some people cling to it like some "security blanket".
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,884
Reputation:
Rep Power: 13
Solved Threads: 197
[EDIT]
I didn't read to carefully. The compiler is so old it doesn't create Win32 exes. You'll have to use a utilit like HiddenStart: http://www.ntwind.com/software/utilities/hstart.html.
The following changes the subsystem type for Win32 exes.
[/EDIT]
If it complains that your exe file is not a PE32 or PE32+ post back and I'll update the program to work with some more ancient Win32 exes.
You should consider using the GCC.
I didn't read to carefully. The compiler is so old it doesn't create Win32 exes. You'll have to use a utilit like HiddenStart: http://www.ntwind.com/software/utilities/hstart.html.
The following changes the subsystem type for Win32 exes.
[/EDIT]
#include <stdio.h>
#include <stdlib.h>
#define then
int main( int argc, char **argv ) {
FILE *f;
unsigned long v = 0;
unsigned short i = 0;
char sig[ 4 ];
if (argc != 2) {
printf( "%s",
"usage:\n"
" chss EXEFILE\n\n"
" Changes the subsystem type of the named exe file and reports the new\n"
" status: console or gui.\n\n"
" The file MUST be a PE32 or PE32+. No checking is done to verify that!\n"
);
return 0;
}
if ((f = fopen( argv[ 1 ], "rb+" )) == NULL) {
fprintf( stderr, "Couldn't open %s", argv[ 1 ] );
return 1;
}
/* addr of PE header signature */
fseek( f, 60, SEEK_SET );
fread( &v, 4, 1, f );
fseek( f, v, SEEK_SET );
fread( sig, 4, 1, f );
if ((sig[ 0 ] != 'P') || (sig[ 1 ] != 'E') || (sig[ 2 ] != 0) || (sig[ 3 ] != 0)) {
fprintf( stderr, "%s is not a PE32 or PE32+", argv[ 1 ] );
return 1;
}
/* addr of subsystem code */
v += 4 + 20 + 68;
/* get current code */
fseek( f, v, SEEK_SET );
fread( &i, 2, 1, f );
if (i == 3)
then {
i = 2;
printf( "%s converted from CONSOLE to GUI subsystem\n", argv[ 1 ] );
}
else {
i = 3;
printf( "%s converted from GUI to CONSOLE subsystem\n", argv[ 1 ] );
}
fseek( f, v, SEEK_SET );
fwrite( &i, 2, 1, f );
fclose( f );
return 0;
}If it complains that your exe file is not a PE32 or PE32+ post back and I'll update the program to work with some more ancient Win32 exes.
You should consider using the GCC.
Last edited by Duoas : Oct 24th, 2007 at 8:01 am.
> #define then
I feel ill just looking at it.
I feel ill just looking at it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,862
Reputation:
Rep Power: 40
Solved Threads: 1013
>>The following changes the subsystem type for Win32 exes
And why in the world would he want to do all that? It isn't necessary just to hide the command window when a console program starts. As Salem mentioned, he can't do it with the compiler he is using and needs to get into the 21st century compiler.
Once you have a compiler that can access win32 api (32-bit compiler) its pretty easy to remove the command window. Your program will need to link with user32.lib, which is supplied with the free-to-download Windows SDK (Software Development Kit)
And why in the world would he want to do all that? It isn't necessary just to hide the command window when a console program starts. As Salem mentioned, he can't do it with the compiler he is using and needs to get into the 21st century compiler.
Once you have a compiler that can access win32 api (32-bit compiler) its pretty easy to remove the command window. Your program will need to link with user32.lib, which is supplied with the free-to-download Windows SDK (Software Development Kit)
#include "windows.h"
...
int main()
{
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
return 0;
}![]() |
Similar Threads
Other Threads in the C++ Forum
- how to call command window with VB.NET programme (VB.NET)
- ActiveMovie Window: explorer.exe - Application Error (Windows NT / 2000 / XP / 2003)
- safe mode info (Windows NT / 2000 / XP / 2003)
- Do i need C to learn C++? (C++)
- Running an exe with a timer (Visual Basic 4 / 5 / 6)
- How to Prevent Command Window from Appearing (C++)
- Un-deletable .exe (Please help ASAP!!) (Windows NT / 2000 / XP / 2003)
- Dont want to display command window (Java)
Other Threads in the C++ Forum
- Previous Thread: Const iterator
- Next Thread: Running C++ program in the background
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode