Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MFC in console application?

Posted on 1998-07-03
4
Medium Priority
?
518 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
[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
  • 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 600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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