-
February 12th, 2014, 04:37 AM
#1
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!
-
February 12th, 2014, 04:55 AM
#2
Re: CoCreateInstance FAILED
Originally Posted by marco.bernasconi
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
-
February 12th, 2014, 05:21 AM
#3
Re: CoCreateInstance FAILED
Originally Posted by Igor Vartanov
The problem can be understood from hr2 exact value, which you did not provide on some reason.
Thanks Igor,
The value is -2147221164.
-
February 12th, 2014, 06:38 AM
#4
Re: CoCreateInstance FAILED
It is REGDB_E_CLASSNOTREG (hex value 0x80040154):
Class not registered
Victor Nijegorodov
-
February 12th, 2014, 06:57 AM
#5
Re: CoCreateInstance FAILED
Originally Posted by VictorN
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.
-
February 12th, 2014, 07:48 AM
#6
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.
-
February 12th, 2014, 09:24 AM
#7
Re: CoCreateInstance FAILED
Originally Posted by OReubens
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!!!
-
February 12th, 2014, 03:34 PM
#8
Re: CoCreateInstance FAILED
Originally Posted by marco.bernasconi
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
-
February 12th, 2014, 03:54 PM
#9
Re: CoCreateInstance FAILED
Originally Posted by Igor Vartanov
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|