Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Add an "ATL Simple Object" to Old ATL DLL Project Upgraded to VS 2010?

We have a DLL project which has existed for a long time (maybe as far back as Visual Studio 6) which has been updated for each new version of VS. The project contains a number COM classes implemented using ATL.

After upgrade to VS 2010, the project still builds fine. However, if I try to right-click the project and choose Add -> Class... -> ATL Simple Object, I get an error box that says this:

ATL classes can only be added to MFC EXE and MFC Regular DLL projects or projects with full ATL support.

This worked in VS 2008.

When I look at the project properties, Use of MFC was set to Use Standard Windows Libraries and Use of ATL was set to Not Using ATL. I changed these to Use MFC in a Shared DLL and Dynamic Link to ATL respectively, but still get the same error.

I know how to add new ATL objects without using the wizard, and I could try to recreate the project from scratch using VS 2010 to make it happy. But does anyone know of any easy way to get VS to allow me to use the ATL Simple Object wizard with a project that it doesn't recognize as a project "with full ATL support"?

like image 540
Kristopher Johnson Avatar asked Dec 21 '11 18:12

Kristopher Johnson


2 Answers

Check this thread out.

It seems that adding this fragment info your ATL C++ code make it work. You don't need to actually build the project, just remove this stuff away after you are done with the wizard (provided that solution works for you).

// Added fake code begins here

class CAppModule : 
    public CComModule
{
};

// Added fake code ends here, below is regular ATL project stuff

CAppModule _Module;

This is where it all comes from, in $(VisualStudio)\VC\VCWizards\1033\common.js:

/******************************************************************************
Description: Returns a boolean indicating whether project is ATL-based.
oProj: Project object
******************************************************************************/
function IsATLProject(oProj)
{
    try
    {
        var oCM = oProj.CodeModel;
        oCM.Synchronize();
        // look for global variable derived from CAtlModuleT
        var oVariables = oCM.Variables;
        for (var nCntr = 1; nCntr <= oVariables.Count; nCntr++)
        {
            var oVariable = oVariables(nCntr);
            var strTypeString = oVariable.TypeString;
            if (strTypeString == "ATL::CComModule" || strTypeString == "ATL::CAutoThreadModule")
            {
                return true;
            }
like image 126
Roman R. Avatar answered Nov 26 '22 12:11

Roman R.


Same problem here, but the project source already had CComModule _Module; Fixed it, based on the IsATLProject script shown above, by changing it to **ATL::**CComModule _Module;

like image 41
Mike Avatar answered Nov 26 '22 13:11

Mike