
Using ShellExecute in VC++
Quote:
>Hello,
>I'm having a problem with the ShellExecute statement in Visual C++ 5.0 Pro. I
>was wandering if maybe someone could help me figure it out.
>My problem is that I cannot seem to get rid of the DOS box, when I launch my
>EXE file. I'm trying to create a simple little EXE that will install an INF
>file under Windows, but I don't want the DOS box to appear.
>Here is my code, maybe someone can tell me what I'm doing wrong:
>#include <windows.h>
>#include <shellapi.h>
>void main(void)
>{
> ShellExecute(NULL,"install","install.inf",NULL,NULL,SW_SHOWNORMAL);
>}
Just use WinMain() instead of main(). Programs using main() are built using
"subsystem:console" (by default, so you get a console). Programs using WinMain()
use "subsystem:windows" (by default). Just because you've used WinMain() doesn't
mean you must do any "windows" things. Just copy the "WinMain(...) {" from an
example and have the program return an integer; no other changes should be
necessary. WinMain() takes arguments that won't be used in your small example
but they must be in the definition (i.e., you can't use "void").
There's another, more complicated way to do it, namely, continue to use main()
but specify "subsystem:windows" (project settings\link) and also specify to the
linker that the program's "entry point" is main() (since "subsystem:windows"
tells the linker to expect to find WinMain()).
- Vince