Solved

Modifying an AppWiz application to be console application

Posted on 1998-02-13
1
231 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 114
cat dog challenge 18 127
Tab names are off by one 5 54
fizzArray  challenge 1 96
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

830 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