locked
64bits: CoCreateInstance 0x80040154 Class not registered RRS feed

  • Question

  • Hi All,

    I am trying to create a COM component for 64bits... so I decide to follow the following article:
    http://www.codeproject.com/Articles/338268/COM-in-C

    I have register my component like that:

    C:\Windows\System32>regsvr32 "C:\NCR\Prueba\sampleCOM\x64\Debug\sampleCOM.dll"

    The project has the following preprocessors:

    _WIN64
    _DEBUG
    _WINDOWS
    _USRDLL
    SAMPLECOM_EXPORTS

    then I have created a console application to call the registered component:

    #include "stdafx.h"
    #include <ObjBase.h>
    #include "../sampleCOM/IsampleCOM.h"

    static const GUID CLSID_Summer = 
    { 0xA90D891B, 0xF628, 0x4952, { 0xBB, 0xD6, 0x3E, 0x4F, 0xCF, 0x96, 0x87, 0xD0 } };

    int _tmain(int argc, _TCHAR* argv[])
    {
    double z=0;
    CoInitialize(NULL);

    ISummer* ps = NULL;
    HRESULT hrA = CoCreateInstance(CLSID_Summer, NULL, CLSCTX_INPROC_SERVER, IID_ISummer, (void**)&ps );

    if (SUCCEEDED(hrA)) {
    printf("===========Summer===========\n");
    ps->Add(5,6,z);
    printf("ps->Add(5,6,z) = %d \n", z);
    ps->Release();
    }


    CoFreeUnusedLibraries();
    return 0;
    }

    but hrA always result in " 0x80040154 Class not registered " not sure what is wrong.

    Can you help me to figure it out what is wrong? or to create a component for 64 bits? 

    Thanks in advance

    Regards

    Sebastian

     
    Monday, March 17, 2014 9:59 PM

Answers

  • Why does Summer::Init call CoCreateInstance with its own CLSID? That ends up calling CreateInstance, which calls Summer::Init, which calls CreateInstance, which calls Summer::Init, which ... Do you see how that might be a problem?


    Igor Tandetnik

    • Marked as answer by smancini Thursday, March 20, 2014 11:50 PM
    Thursday, March 20, 2014 9:23 PM

All replies

  • Make sure your console application is also built for 64-bit.

    Igor Tandetnik

    Monday, March 17, 2014 11:23 PM
  • Hi Sebastian,

    Please check if it can be registered successfully.

    Reregistered the component.

    Please change "CLSCTX_INPROC_SERVER" to "CLSCTX_ALL" if the steps above can not work for you.

    Best regards,

    Sunny

    Wednesday, March 19, 2014 7:16 AM
  • Thanks Sunny and Igor for answer... I have continue making tries with no good results.

    My factory object has the method CreateInstance that way:

    HRESULT rc = E_UNEXPECTED;

    if (pUnk != NULL) rc = CLASS_E_NOAGGREGATION;
    else if (IsEqualIID(id, IID_ISummer) || IsEqualIID(id, IID_IUnknown))
    {
    Summer* sum;
    if ((sum = new Summer()) == NULL)
    rc = E_OUTOFMEMORY;
    else
    rc = sum->Init();

    if (FAILED(rc)) {
    // initialization failed, delete component
    sum->Release();
    return rc;
    }

    rc = sum->QueryInterface(id,ppv);
    sum->Release();
    return rc;
    }
    return rc;

    It seems that this method is called many times internally... and it is not working in this line:

    rc = sum->Init();

    HRESULT Summer::Init() {
    HRESULT rc;
    rc = CoCreateInstance(CLSID_Summer, NULL, CLSCTX_ALL, IID_ISummer, (void**)&summer);
    return rc;
    }

    The CoCreateInstance in here is throwing error:

    Unhandled exception at 0x774f3520 (ntdll.dll) in CalculateClient.exe: 0xC00000FD: Stack overflow.

    The Stack shows the following:

      ole32.dll!CComCatalog::GetClassInfoInternal(unsigned long flags, IUserToken * pUserToken, const _GUID & guidConfiguredClsid, const _GUID & riid, void * * ppv, void * pComCatalog)  Line 2163 C++
      ole32.dll!CComCatalog::GetClassInfoW(unsigned long flags, IUserToken * pUserToken, const _GUID & guidConfiguredClsid, const _GUID & riid, void * * ppv)  Line 726 C++
      ole32.dll!LookForConfiguredClsid(const _GUID & RefClsid, _GUID & rFoundConfClsid, unsigned long dwActvFlags)  Line 1041 C++
      ole32.dll!ICoCreateInstanceEx(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, unsigned long dwActvFlags, tagMULTI_QI * pResults, ActivationPropertiesIn * pActIn)  Line 1146 + 0x19 bytes C++
      ole32.dll!CoCreateInstance(const _GUID & rclsid, IUnknown * pUnkOuter, unsigned long dwContext, const _GUID & riid, void * * ppv)  Line 108 + 0x12c bytes C++
    > Calculate.dll!Summer::Init()  Line 64 + 0x2a bytes C++

    Not sure how to resolve or what is wrong in here... Any help?

    Thursday, March 20, 2014 9:15 PM
  • Why does Summer::Init call CoCreateInstance with its own CLSID? That ends up calling CreateInstance, which calls Summer::Init, which calls CreateInstance, which calls Summer::Init, which ... Do you see how that might be a problem?


    Igor Tandetnik

    • Marked as answer by smancini Thursday, March 20, 2014 11:50 PM
    Thursday, March 20, 2014 9:23 PM
  • Yes... I see, you are right. The example i am using as a base in is a bit confusing... my intention is to make a simple COM object and seems that the Init() call is not needed at all. right?

    The line:

    rc = sum->QueryInterface(id,ppv);

    seems to be enough to init the object.

    I have remove the call to that init() method and now is working... I also have to remove some lines include in the original example that were introducing errors and are no so clear.

    Really thanks for the help you gave it to me Igor!!

    Regards

    Sebastian.

    Thursday, March 20, 2014 11:44 PM