Solved

MFC Support in ATL Projects.

Posted on 2004-04-07
2
888 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
[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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…

739 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