Solved

Modifying an AppWiz application to be console application

Posted on 1998-02-13
1
224 Views
Last Modified: 2013-11-20
Is it possible to modify a standard program generated
by the AppWizard so it can be started As a console application?

It also has to be able to accept input :  
 main(int argc, char **argv)

and the AppWizard program can't be a spawned
process of the console app.

Thanks,

Eric
0
Comment
Question by:nielsew
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 20 total points
ID: 1316172
It is possible, but it's not worth the trouble--you end up removing ten times more than you would use.

I don't understand your requirement that "the AppWizard program can't be a spawned process of the console app". I can't reconcile your statement: a console application is free to create windows, so that can't be what you mean.  And a console app can spawn a /SUBSYSTEM:WINDOWS application any time it wants to.  So, that can't be what you mean.

What is it that you're really trying to say?

You don't mention which version of which development environment you're using, so I'll assume you're using VC++ 5.0. Anyhow, to get an MFC app that runs as a console, you should:

1) Ask for a new "Win32 Console Application"
2) In the resulting project, use the "Settings" command in the "project menu"
3) Make sure "All Configurations" is selected in the "Settings For" box
4) In the "Microsoft Foundation Classes" drop down, select either "in a Shared DLL" or "in a static library"--whichever you like.
5) Press OK to close the "Project Settings" dialog
6) Create a new *.CPP file.  Name it whatever you like.
7) Add the *.CPP file you created to your project.
8) Edit the *.CPP file.  Put this code in it:

#include <afx.h>
#include <afxwin.h>

CWinApp theApp;

int main(int argc, char* argv[])
{
   int nRetVal = 1;

   if (!AfxWinInit(GetModuleHandle(), NULL, GetCommandLine(), 0))
   {
      // MFC failed to initialize.
      printf("startup error!");
   }
   else
   {
      // your app is up!  make whatever Win32 API, standard lib,
      // or MFC calls you'd like.

      CString str("Hello");
      printf("%s world!\n", (LPCTSTR) str);
      nRetVal = 0;
   }

   return nRetVal;
}

9) Save it.
10) Build it.

You're in business.

.B ekiM



0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now