Solved

How to include MFC in a Console application

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

774 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