Solved

MFC Support in ATL Projects.

Posted on 2004-04-07
2
864 Views
Last Modified: 2013-11-25
I have a ATL COM Object in the form of a DLL. It has a ton of interface functions and heavily uses string processing and does not process any kind of window messages and has no GUI objects.

In order to simplify string processing, I used CStrings. For which I had to enable MFC support in my ATL-COM DLL using the help of MSDN KB Article Q173974 (Add MFC Support to an ATL Project).

This article suggests the following:

Add the following line of code to the beginning of every member function of a COM interface, window procedure, and exported function:

AFX_MANAGE_STATE(AfxGetAppModuleState());


As far as I understand, AFX_MANAGE_STATE is used so that MFC can load proper resources form the DLL in which the function recides, rather than from the EXE module.

Since I am using only the CString from MFC (and not using the CString::LoadString() anywhere in my code), do I need to include AFX_MANAGE_STATE(AfxGetAppModuleState());  in all my interface function.

In short, my question is if I am only using CString from MFC and not using any resource, do I still need AFX_MANAGE_STATE(AfxGetAppModuleState());  line in all my interface function. If the answer is "YES" why so.


TIA,
Itti.

0
Comment
Question by:ittijindani
2 Comments
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 250 total points
ID: 10776016
>As far as I understand, AFX_MANAGE_STATE is used so that MFC can load proper resources form the DLL in which the >function recides, rather than from the EXE module.

AFX_MANAGE_STATE( AFX_MODULE_STATE* pModuleState )

is the definition in MSDN for AFX_MANAGE_STATE

It is not for any DLL or EXE. It is specified as something related to 'MODULE' which can be exe or dll.

>Add the following line of code to the beginning of every member function of a COM interface, window procedure, and >exported function:

You find this in MSDN article becoz this is required if you are using any MFC resources in your COM interfaces or the window procedures or in the exported methods. Else the application using your component ( exe or dll ) will not be able to load the MFC resources.

>In short, my question is if I am only using CString from MFC and not using any resource, do I still need >AFX_MANAGE_STATE(AfxGetAppModuleState());  line in all my interface function

I think you need not ,if you are using just CString . This will be available in the shared library of MFC which your ATL Server is linking to. Unless you need to load any resources from MFC like Dialog, you need not add this line.

The problem with CString is you need to include MFC support to your ATL server just to get the CString class. However, this defeats ATL's goal of producing small, efficient, high-performance servers - and it's not necessary!!!
Plz have a look at the following article
http://www.codeguru.com/Cpp/COM-Tech/atl/atl/article.php/c67/

-Lakshman
0
 

Author Comment

by:ittijindani
ID: 10776667
Laxman,

Thanks a lot. I also beleive what you said in your answer to my question.

I understand that including MFC for CString defeates the purpose of efficient ATL code, but since I was working on enhancement of some code that was written by somebody else, I thought that I would re-confirm my understanding.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 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

15 Experts available now in Live!

Get 1:1 Help Now