Solved

How to include MFC in a Console application

Posted on 2001-08-08
5
1,283 Views
Last Modified: 2013-11-20
I'm working with a Visual C++ 6 Console Application on Win98.
I have to add DataBase classes with DAO support.
How can I include MFC in my project, so I can derive CDAORecordset?
Best regards,
Chris
0
Comment
Question by:cbonjovi
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 25 total points
ID: 6364221
See http://support.microsoft.com/support/kb/articles/q152/6/96.asp ('HOWTO: Using the MFC Database Classes in Console Applications')
0
 
LVL 1

Assisted Solution

by:jizhang
jizhang earned 25 total points
ID: 6365102
Use Visual Studio togenerate your Console prog codes:

New ->
Projects->Win32 Console Application
select:  An application that supports MFC

generate codes, it would look like:

// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
     int nRetCode = 0;
     // initialize MFC and print and error on failure
     if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
     {
          // TODO: change error code to suit your needs
          cerr << _T("Fatal Error: MFC initialization failed") << endl;
          nRetCode = 1;
     }
     else
     {
          // TODO: code your application's behavior here.
          CString strHello;
          strHello.LoadString(IDS_HELLO);
          cout << (LPCTSTR)strHello << endl;
     }
     return nRetCode;
}

Now, you can use any  MFC's classes to do whatever you want.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6365492
I always cheated (using ODBC).
I made two projects.
One that is the console app and one that is a CFormView app.
I would build the ODBC classes in the CFormView so I could use the class wizard.  Then I would copy the class out of one project and insert it into the other.

Once you have the classes defined, it's pretty much the same as a GUI.
0
 

Expert Comment

by:Thomas_Dzieran
ID: 6376212
If you didn't chose MFC support option when you created
your console application, you can still add it:

in your stdafx.h file add
#include <afxwin.h>
#include <afxdao.h> //for Dao support.

Go to project/settings.
In C/C++ tab, in the category field choose:
 "Code Generation"
In the "Use run-time library" field, choose:
 "Debug Multithreaded"
Rebuild you project.

Now you can use MFC and work with DA0
(create db, recordset, etc.).
Let me know if it helps.
Thomas Adam Dzieran
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9521157
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: jkr, jizhang (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countEvens challenge 2 58
only14 challenge 19 64
sumHeights  challenge 17 61
Question on web subscription for apps 3 73
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

757 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

23 Experts available now in Live!

Get 1:1 Help Now