Solved

MFC in console application?

Posted on 1998-07-03
4
498 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Excuse the typo in my answer. The second sentence should start "Note that sockets..."
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

9 Experts available now in Live!

Get 1:1 Help Now