Member Avatar


I am trying to use an OCX control in a console application and I have been doing some reading from the following post

In the following statement

HRESULT hr = CoCreateInstance(CLSID_Registration, 0, CLSCTX_ALL, IID__Registration, reinterpret_cast<void**>(&preg));

hr has the value Class is not licensed for use.

I tried registering the ocx and I still have the issue. How do i overcome this problem?


Recommended Answers

All 3 Replies

Member Avatar

Also when I imported the ocx file, VC++ generated a .tlh file and there was no .tli file. Why is this?


> there was no .tli file. Why is this?

The .tli contains generated inline member functions that wrap the interface methods.

No .tli file is generated id you suppressed it's generation by using the raw_interfaces_only attribute in the #import directive.

> When I was trying to instantiate the COM object i kept getting an error -
> class not licensed for use. I was however able to find a registry script
> that added the license to the registry and I am able to use the ocx.

1. Use CoGetClassObject() to get the IClassFactory2 interface of the class object.

2. Invoke IClassFactory2::CreateInstanceLic() to create the instance

Something like

IClassFactory2* factory = 0 ;
HRESULT hr = ::CoGetClassObject( CLSID_Registration, CLSCTX_INPROC_SERVER, 0, 
                                 reinterpret_cast<void**>(&factory) ) ;
if( SUCCEEDED(hr) )
    IRegistration* reg = 0 ;
    hr = factory->CreateInstanceLic( 0, 0, IID__Registration, 
                                     "put the license string here",
                                     reinterpret_cast<void**>(&reg) ) ;
    if( SUCCEEDED(hr) )
    // etc

> Can you please shed some light on as to what that license is meant to do
> and how it is created?


> I would like to learn more about COM and ActiveX controls.
> Do you have any books that I can refer to.

Start with 'Inside Com'

Then read Don Box
and 'Understanding ActiveX and OLE'

Member Avatar

Thanks Vijayan121. The ocx I am using has a return data type DATE and I am not able to determine an equivalent data type in C++ that can handle DATE. Could you please tell me what I should be using?

virtual HRESULT __stdcall get_LicenseEnd (
        /*[out,retval]*/ DATE * _arg1 ) = 0;

Thanks once again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.