views:

997

answers:

3

I did some googling to try to answer this question but even after that I'm not quite clear about something. Is it possible to create a console app from VB6?

I've got a VB6 app that doesn't put up a window. I always assumed that it was a console app. However, I want to be able to use the Windows API SetConsoleCtrlHandler function from within it. I believe that with C++/MFC apps you have to set a linker switch to create a console app. And one of my fellow developers told me that VB6 doesn't create a true console app and therefore this would not work. So is it possible to create a console app that Windows will recognize as a console app from VB6?

Platform: Windows XP SP2

Development Platform: VB6

+5  A: 

Yes. It's also possible to create totally headless applications (which I've done a few times in the past). This link gives an example with a code snippet.

ConcernedOfTunbridgeWells
@NXC, Thanks--that's just what the doctor ordered.
Onorio Catenacci
+1  A: 

See this article.

Or you could rewrite the VB6 app as a VBScript program.

Patrick Cuff
Thanks Patrick--that's helpful.
Onorio Catenacci
+3  A: 

You can use Karl E. Peterson's code at http://vb.mvps.org/samples/project.asp?id=Console to create a very full-featured console application.

Simpler ones can be made by relinking the compiled VB6 EXE for the console subsystem. Karl goes into this at that same Web page. Scroll down for LinkConsole.vbs there.

Bob
Yeah, I think that is how I did it in my time: You really have to tell the .exe that its a console app - that must be done in a post-compilation step (make is your friend?).
Daren Thomas
As of 31 march, Karl Peterson's code is also available wrapped in a free add-in called vbAdvance (with many other powerful features). http://vb.mvps.org/tools/vbAdvance/
MarkJ
Karl did a great job, as always. However that's a large slab of lard (overhead) for making most console programs. You seldom need most of what he supplied. The good news is you have the source so you can trim it down as required.
Bob