Solved

How to include MFC in a Console application

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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
API Soap Calls 4 126
Problem to ToolkitScriptManager 2 67
Fixed div within Bootstrap carousel item 11 61
x-bar in Google Sheets 2 69
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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 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…

809 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