Solved

MFC in console application?

Posted on 1998-07-03
4
513 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

861 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