MFC Support in ATL Projects.

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.

>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*

>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 articlehttp://www.codeguru.com/Cpp/COM-Tech/atl/atl/article.php/c67/

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.

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 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…