[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to include MFC in a Console application

Posted on 2001-08-08
5
Medium Priority
?
1,373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 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 100 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

656 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