locked
VS2010 ATL bug?? RRS feed

  • Question

  • MS promised to fix this regression issue in the next release or upgrade, but MS did not in vs10 sp1.

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    I created a simple ATL service project, added a simple ATL object, but register class always fail. I debuged ATL source code, and found CoInitializeEx(...) was not called. While ATL shipped with VS2008 does call CoInitializeEx(...) by itself. why this happened? is it a code defect?

     

    How to repro:

    Set a breakpoint at "hRes = CoRegisterClassObject(*pclsid, p, dwClsContext, dwFlags, &dwRegister);" @line207 in atlbase.h to check the return value

    -- hRes 0x800401f0 CoInitialize has not been called. --

    Hope it be clear enough for the problem.

     

    thanks,

    song.min@live.com

     

    • Edited by Smart Gotodo Thursday, March 10, 2011 3:49 PM ms did not keep his promise
    Tuesday, April 13, 2010 3:49 PM

Answers

  • finanly fixed in vs2011 developer preview.
    • Marked as answer by Smart Gotodo Monday, December 5, 2011 8:38 AM
    Monday, December 5, 2011 8:37 AM

All replies

  • CoInitializeEx() is called in line 3370 of atlbase.h, inside CAtlExeModuleT<>::InitializeCOM().

    This has nothing to do with your problem.

    If you can't register the ATL service, the first thing I would suspect is that you are using either Vista or Windows 7 but not explicitly opening Visual Studio as an Administrator.

     

     

    Tuesday, April 13, 2010 4:22 PM
  • Hi Min,

    There is another ATL Simple Object class wizard change in VS2010: The ProgID field will not be automatically filled as you fill in the "Short name:" text box.

    This product change is due to security reasons.

    Jianhua 

     

     

    Tuesday, April 13, 2010 5:36 PM
  • Thank you Muth & Jianhua.

    But I do not think you got me. Here is the code difference:

    VS2010 ATL - CAtlExeModuleT::CAtlExeModuleT() DOES NOT call T::InitializeCom()

    VS2008 ATL - CAtlExeModuleT::CAtlExeModuleT() DOES call T::InitializeCom()

    Since T::InitializeCom() is not called in VS2010, _ATL_OBJMAP_ENTRY30::RegisterClassObject(…) failed.

    I think the problem could be resolved by manually call T::InitializeCom(). But I cannot figure out why VS2010 ATL removed the call?

    Wednesday, April 14, 2010 3:50 AM
  • I created an ATL server with a simple ATL object and it registered just fine.

    Why not answer a few questions...

    Are you running under Vista or Windows 7?

    If so, did you try opening Visual Studio 2010 by right-clicking on the icon, and selecting "Run As Administrator"? If you rebuild, does it register successfully?

    Wednesday, April 14, 2010 5:43 AM
  • Muth, I run VS2010 with buil-in administrator under Windows 2008 R2 EE. I have also tried 'Run as administrator', it sill did not work. I am sure my VS is 2010 ultimate RTM, is your VS2010 ATL source diffent with mine?
    Wednesday, April 14, 2010 6:48 AM
  • The problem resolved by  mannuly adding  _AtlModule.InitializeCom() as below:

    extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/,
                                    LPTSTR /*lpCmdLine*/, int nShowCmd)
    {
      _AtlModule.InitializeCom();
        return _AtlModule.WinMain(nShowCmd);
    }

    Can any MS guys tell me why CAtlExeModuleT::CAtlExeModuleT() DOES NOT call T::InitializeCom() in VS2010 ATL??

    Wednesday, April 14, 2010 12:52 PM
  • Hi smartgtd,

    I tried to create a ATL service application, add a ATL simple object to it, and then build the application. Everything is fine on my AMD64 Windows Server 2008 R2 Enterprise machine.  

    Could you share the details to reproduce this issue? Like what exactly did you do when you create the ATL project, and add the ATL simple object class? Do you have other side by side VS/Express product installed on your machine?

    By the way, I have reported the "InitializeCom" issue to our team and I will keep you udpated.

    Thanks,

    Jianhua

    Wednesday, April 14, 2010 5:35 PM
  •  I am sure my VS is 2010 ultimate RTM.
    The retail version of VS 2010 was just launched on April 12th. Did you just acquire the ISO this week? I just want to be sure that you have the correct version, since as far as I know there is no designation "RTM".
    Wednesday, April 14, 2010 8:21 PM
  • By the way, I have reported the "InitializeCom" issue to our team and I will keep you udpated.

    I got comfirmation from our senior team member:

    This is by design.  There was no need for COM to be initialized in the constructor, and it could lead to unbalanced calls.

    The COM initialization was moved to the WinMain and ServiceMain methods so that it was only called once.

     

    Wednesday, April 14, 2010 9:38 PM
  • Jianhua thank you, I see.

    But ATL generated code did not call InitCOM, right? or can you tell me where InitCOM is called inside ATL source code?

    extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/,
                                    LPTSTR /*lpCmdLine*/, int nShowCmd)
    {
      _AtlModule.InitializeCom();
        return _AtlModule.WinMain(nShowCmd);
    }

     

     

    Thursday, April 15, 2010 3:24 AM
  • In fact, no special procedure to repro it, but it can 100% repro on my machine. anyway, the repro steps:

    1) i have vs2008 and win7 SDk installed before

    2) unintall vs2008 and win7 SDK

    3) dowload vs2010 ultimate final release from MSDN

    4) install vs2010

    5) New ATL service project (click next until finish)

    6) Add A simple ATL object (Free, Dual interface, click next until finish)

    7) Build

    Issue occured.

    Thursday, April 15, 2010 3:38 AM
  • I've repeated those steps. I'm unable to reproduce.

    Have you tried using a different workstation?

    Thursday, April 15, 2010 4:08 PM
  • I've repeated those steps. I'm unable to reproduce.

    Have you tried using a different workstation?


    I did not try on different workstation.

    Could you please mail your code to me song.min@live.com ? I will try your code on my machine.

    Friday, April 16, 2010 9:44 AM
  • I repro it on my another win03 machine. Can you set a breakpoint at "hRes = CoRegisterClassObject(*pclsid, p, dwClsContext, dwFlags, &dwRegister);" @line207 in atlbase.h to check the return value?

    --  hRes 0x800401f0 CoInitialize has not been called.  --

    Hope it be clear enough for the problem.

    Monday, April 19, 2010 7:01 AM
  • Jianhua thank you, I see.

    But ATL generated code did not call InitCOM, right? or can you tell me where InitCOM is called inside ATL source code?

    extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/,
                                    LPTSTR /*lpCmdLine*/, int nShowCmd)
    {
      _AtlModule.InitializeCom();
        return _AtlModule.WinMain(nShowCmd);
    }


    Hi Min,

    As I replied in this post:

    This is by design.  There was no need for COM to be initialized in the constructor, and it could lead to unbalanced calls.

    The COM initialization was moved to the WinMain and ServiceMain methods so that it was only called once.

    To answer your question, I checked my ATL source and the "InitializeCom()" is called at the following locations in file "atlbase.h"

    1. Line 3453, hr = T::InitializeCom(); inside function "int WinMain(_In_ int nShowCmd) throw()"
    2. Line 3886, hr = T::InitializeCom(); inside function "void ServiceMain(_In_ DWORD dwArgc, _In_count_(dwArgc) _Deref_pre_z_ LPTSTR* lpszArgv) throw()"

    Thanks,

    Jianhua

    Tuesday, April 20, 2010 4:52 PM
  • I repro it on my another win03 machine. Can you set a breakpoint at "hRes = CoRegisterClassObject(*pclsid, p, dwClsContext, dwFlags, &dwRegister);" @line207 in atlbase.h to check the return value?

    --  hRes 0x800401f0 CoInitialize has not been called.  --

    Hope it be clear enough for the problem.


    Hi Min,

    I am able to reproduce the problem on my clean dev box.

    However, I see the registration failure message at line 3958 in file atlbase.h, which has the following code:

    hr = pT->RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);

    While I debugged, I saw hr         0x800401f0 CoInitialize has not been called.         HRESULT

    I have convey this issue to our team, and will update you once I get some replies.

    Thanks,

    Jianhua

    Tuesday, April 20, 2010 7:38 PM
  • Hi Min,

    Just let you know that we have opened a product bug for the issue you reported.

    We will fix it in next product release or update.

    Currently, please use your workaround to unblock your work. We are sorry for this inconvenience.

    Thanks again for reporting this issue.

    Jianhua

    • Marked as answer by Smart Gotodo Wednesday, April 21, 2010 3:38 AM
    • Unmarked as answer by Smart Gotodo Thursday, March 10, 2011 3:45 PM
    Tuesday, April 20, 2010 11:17 PM
  • finanly fixed in vs2011 developer preview.
    • Marked as answer by Smart Gotodo Monday, December 5, 2011 8:38 AM
    Monday, December 5, 2011 8:37 AM