CoCreateInstance returns 0x80080005 for Visual Studio 2008 based ATL service??

CoCreateInstance returns 0x80080005 for Visual Studio 2008 based ATL service??

I just worked with a customer who was facing interesting issue. He was getting 0x80080005 at client when he calls CoCreateInstance. The COM component is implemented within an ATL Service which is running on the same machine (we are not hitting wire/network). Now, typical meaning of this error is,

CO_E_SERVER_EXEC_FAILURE                                      winerror.h
Server execution failed

Generally this means Server (out of process server, either stand alone EXE or service) did not respond to RPCSS within definite time about COM server's successful start. Many things could have happened (may be Server got some exception/error, or server got crashed!)

But in this case, even if I start the service before making call from client, I get same response from client. Something else was wrong! And after lots of checks here and there, we found out that it is a BUG!

The bug shows up when,

  • You create a brand new ATL Service project using Wizard with Visual Studio 2008.

The root cause is, newly generated CoClass's rgs file (that holds the component registration information) doesn't contain entry for AppID. So, even if you register the COM component (using <exename.exe> /service), you dont get AppID key generated for CoClass. And COM runtime returns this error at client.

To fix it,

  • Look at your rgs file (for each ATL simple objects you added to COM service project),
  • Replace snippet looking similar to following,

                ForceRemove {9ACB97C6-4492-40E8-A1BD-51DFE8962E92} = s 'CMyObject Class'

                {

                      ProgID = s 'ATLComService.CMyObject.1'

                      VersionIndependentProgID = s 'ATLComService.CMyObject'

                      ForceRemove 'Programmable'

                      LocalServer32 = s '%MODULE%'

                      'TypeLib' = s '{E423A7DE-58C7-4535-A864-395DCEDE941F}'

                }

    with 

                ForceRemove {9ACB97C6-4492-40E8-A1BD-51DFE8962E92} = s 'CMyObject Class'

                {

                      ProgID = s 'ATLComService.CMyObject.1'

                      VersionIndependentProgID = s 'ATLComService.CMyObject'

                      ForceRemove 'Programmable'

                      LocalServer32 = s '%MODULE%'

                      val AppID = s '%APPID%'

                      'TypeLib' = s '{E423A7DE-58C7-4535-A864-395DCEDE941F}'

                }

There is also another way to permanently fix this issue (Product Team is planning to fix this issue in Visual Studio 2008 SP1), you can also,

  • Go to C:/Program Files/Microsoft Visual Studio 9.0/VC/VCWizards/CodeWiz/ATL/Simple/Templates/1033/object.rgs
  • Add following line right before statement for "typelib"

    [!if APPID_EXIST]

                                        val AppID = s '[!output APPID_REGISTRY_FORMAT]'

    [!endif]

That should fix the issue.

Stay tuned.. Wave

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值