Solved

How to include MFC in a Console application

Posted on 2001-08-08
5
1,300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
installing and using WTP plugin eclipse MARS 3 99
sum67 challenge 35 93
tripleUp challenge 7 74
Select distinct 25 83
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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 how to look for a specific file type in a local or remote server directory using PHP.

920 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

16 Experts available now in Live!

Get 1:1 Help Now