Solved

MFC Support in ATL Projects.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Convert GUI app into console app for Win32 Env 5 125
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,249
Increment column based of a FK 8 47
Input parameteres to DragOver 2 34
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…

680 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