- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From time to time, we get questions from users asking how to do what Developer Studio does when you run a console program, in that, when the program finishes, it prompts with "Press any key to continue"
The attachment (if this works) is a program I whipped up that shows how to do this in an, if I do say so myself, elegant manner. I plan on incorporating this into an article for our next newsletter, and would appreciate any comments folks here have to offer.
Steve
The attachment (if this works) is a program I whipped up that shows how to do this in an, if I do say so myself, elegant manner. I plan on incorporating this into an article for our next newsletter, and would appreciate any comments folks here have to offer.
Steve
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I was one of those who asked at one point in time. :-) After that, I wrote a little utility to launch console apps from Explorer and keep the console window up when done. Anyone can check it out here.
Steve, I like what you did. It looks like an easy way to build the capability automatically into any console app.
FWIW, I always pass NULL for the lpApplicationName parameter to CreateProcess and instead build a complete command line, including the path to the exe, in the lpCommandLine parameter. This habit comes both from bad experience and reading the chapter on processes in Richter's book.
Note that you probably also want to deal with the possibility of spaces in the exe's path (regardless of which parameter you put it in).
There may also be an issue with the lpCommandLine arg about string literals going into read-only memory and an access violation when the implementation of CreateProcess modifies the string (and later changes it back). Shouldn't be a problem on NT/2000 since CVF maps the call to CreateProcess to CreateProcessA, and the system makes a copy of the string when it eventually calls CreateProcessW behind the scenes. But, I haven't tested this on Win9x (which calls CreateProcessA directly).
Cheers,
John
Steve, I like what you did. It looks like an easy way to build the capability automatically into any console app.
FWIW, I always pass NULL for the lpApplicationName parameter to CreateProcess and instead build a complete command line, including the path to the exe, in the lpCommandLine parameter. This habit comes both from bad experience and reading the chapter on processes in Richter's book.
Note that you probably also want to deal with the possibility of spaces in the exe's path (regardless of which parameter you put it in).
There may also be an issue with the lpCommandLine arg about string literals going into read-only memory and an access violation when the implementation of CreateProcess modifies the string (and later changes it back). Shouldn't be a problem on NT/2000 since CVF maps the call to CreateProcess to CreateProcessA, and the system makes a copy of the string when it eventually calls CreateProcessW behind the scenes. But, I haven't tested this on Win9x (which calls CreateProcessA directly).
Cheers,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the comments, John.
Spaces in the path name don't seem to matter if you put it in lpApplicationName - they would if put in the command line. I'll switch to that method instead. I don't know of any problems with the string being readonly.
Steve
Spaces in the path name don't seem to matter if you put it in lpApplicationName - they would if put in the command line. I'll switch to that method instead. I don't know of any problems with the string being readonly.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
You're right about spaces in lpApplicationName. Sorry.
For the read-only string literal thing, I was looking at a comment in Richter's book (latest edition), but it may only be a problem for unicode (see MSKB Q199290). Sorry for confusing matters.
-John
You're right about spaces in lpApplicationName. Sorry.
For the read-only string literal thing, I was looking at a comment in Richter's book (latest edition), but it may only be a problem for unicode (see MSKB Q199290). Sorry for confusing matters.
-John

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page