?
Solved

MFC Support in ATL Projects.

Posted on 2004-04-07
2
Medium Priority
?
915 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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: 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 …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…

749 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