CoCreateInstance FAILED
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: CoCreateInstance FAILED

  1. #1
    Join Date
    Nov 2013
    Location
    Milan [.NET 4.5]
    Posts
    17

    CoCreateInstance FAILED

    Hi all,

    I'm following a sample from a third part SDK.

    In particular this piece of code:


    Code:
    CComPtr<INVRAdapter> _adapter;
    
    CLSID clsOCAdapter;
    HRESULT hr1 = CLSIDFromProgID(L"OnSSI.OCAdapter.1", &clsOCAdapter);
    
    HRESULT hr2 = CoCreateInstance(clsOCAdapter,
    		NULL,
    		CLSCTX_INPROC_SERVER,
    		__uuidof(INVRAdapter),
    		(void**)&_adapter);
    
    if (FAILED(hr2))
    {
    
    //code
    }

    The result is that hr2 is negative, so it fails.

    I've checked in the registry and the OnSSI.OCAdapter.1 record exists.


    What's the problem?

    Thank you very much!

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: CoCreateInstance FAILED

    Quote Originally Posted by marco.bernasconi View Post
    What's the problem?
    The problem can be understood from hr2 exact value, which you did not provide on some reason.

    Most probably you do not initialize COM on the thread.

    Besides, as long as you deal with CComPtr, your code might look just like
    Code:
    CComPtr<INVRAdapter> _adapter;
    HRESULT hr = _adapter.CoCreateInstance(L"OnSSI.OCAdapter");
    Best regards,
    Igor

  3. #3
    Join Date
    Nov 2013
    Location
    Milan [.NET 4.5]
    Posts
    17

    Re: CoCreateInstance FAILED

    Quote Originally Posted by Igor Vartanov View Post
    The problem can be understood from hr2 exact value, which you did not provide on some reason.
    Thanks Igor,

    The value is -2147221164.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,288

    Re: CoCreateInstance FAILED

    It is REGDB_E_CLASSNOTREG (hex value 0x80040154):
    Class not registered
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2013
    Location
    Milan [.NET 4.5]
    Posts
    17

    Re: CoCreateInstance FAILED

    Quote Originally Posted by VictorN View Post
    It is REGDB_E_CLASSNOTREG (hex value 0x80040154):
    Class not registered

    Mmmh...in the registry (HKEY_LOCAL_MACHINE/SOFTWARE/Classes) I see OnSSI.OCAdapter.1.

    I've registered it using regasm.

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,765

    Re: CoCreateInstance FAILED

    If it's in-process... Are you sure the bitness of your app is the same as the bitness of your registered COM object ?

    you can't call a 64bit in-process COM object from a 32bit app and vice versa.

  7. #7
    Join Date
    Nov 2013
    Location
    Milan [.NET 4.5]
    Posts
    17

    Re: CoCreateInstance FAILED

    Quote Originally Posted by OReubens View Post
    If it's in-process... Are you sure the bitness of your app is the same as the bitness of your registered COM object ?

    you can't call a 64bit in-process COM object from a 32bit app and vice versa.

    That's the trick!!!




    Thanks!!!

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: CoCreateInstance FAILED

    Quote Originally Posted by marco.bernasconi View Post
    That's the trick!!!
    What's the trick? HRESULT never lies. In case it says Class not registered, the class is not registered. 64-bit and 32-bit processes have different registry hives for COM class registration.
    Best regards,
    Igor

  9. #9
    Join Date
    Nov 2013
    Location
    Milan [.NET 4.5]
    Posts
    17

    Re: CoCreateInstance FAILED

    Quote Originally Posted by Igor Vartanov View Post
    What's the trick? HRESULT never lies. In case it says Class not registered, the class is not registered. 64-bit and 32-bit processes have different registry hives for COM class registration.
    I didn't know that there are different registries for COM class.

    I'm not a guru in this field

    Thanks for all!

    Marco

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center