Solved

MFC in console application?

Posted on 1998-07-03
4
504 Views
Last Modified: 2013-11-19

What parts of MFC (if any) can be used in an application
without a CWinApp-derived class (no message pump)?

This is a list of things I've been using:
* CFile, CSocketFile
* CArchive
* the Internet services (CInternetSession)
* simple value types (CString, CTime, ...)
* Windows sockets (CAsyncSocket/CSocket)
* different synchronisation objects (CEvent, CMutex, ...)

Am I right to assume that these will work correctly
in, for example, a simple console application provided I
pull in the correct header files and link with MFC?

If not, why? For 200 points I expect more than a Yes/No
answer. :-)  (A nice URL or a chapter in any of the more
famous MFC books is also accepted.)

If yes, what other MFC classes works correctly in an
environment without CWinApp/message pump?
0
Comment
Question by:Daniel_E
  • 2
4 Comments
 

Expert Comment

by:zingo
ID: 1318714
Yes. This is how I do it:

1. Create a console application
2. Change run-time library to Multi-threaded DLL (in Project -> Settings)
3. Add the defines _AFXDLL and _MBCS (in Project -> Settings)
4. Copy the files StdAfx.cpp and stdafx.h to your project from a MFC project
5. Include stdafx.h in your source files and StdAfx.cpp in your project
6. Go ahead and use MFC (non-gui classes)

These are the classes I have used in this way:

CString, CObArray, CAsyncSocket, and some more.

I expect that all non-gui classes would work.

Good luck!
0
 
LVL 1

Author Comment

by:Daniel_E
ID: 1318715
I'm sorry zingo, but you didn't actually answer the question. I'm
therefore reopening it to other experts.

I wasn't looking for confirmation that it _might_ work. I'm
already using MFC in console apps and regular DLLs (I'm sorry if
this wasn't clear). I'm looking for hard proof that it _will_
work, and possibly a list of exactly which classes can be used
without CWinApp/message pump. I'll rephrase the question to make
this clear.

You're more than welcome to re-answer it if you feel you can
provide me with the information I'm looking for.

Thanks anyway!

0
 
LVL 3

Accepted Solution

by:
tma050898 earned 200 total points
ID: 1318716
Daniel,

I don't know of any source that goes through every one of the hundreds of MFC classes specifying which ones can be used in console apps. However, here's the list that you presented. Not that sockets can be used from a console application if you manually create the message pump yourself. I had to do this once a couple of years ago when I needed to use sockets from an NT service.

* CFile, CSocketFile = can be used
* CArchive = can be used
* the Internet services (CInternetSession) = can be used
* simple value types (CString, CTime, ...) = can be used
* Windows sockets (CAsyncSocket/CSocket) = can NOT be used
* different synchronisation objects (CEvent, CMutex, ...) = can be used

Tom

0
 
LVL 3

Expert Comment

by:tma050898
ID: 1318717
Excuse the typo in my answer. The second sentence should start "Note that sockets..."
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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

18 Experts available now in Live!

Get 1:1 Help Now