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?


Re: Using OCX in console application 80 80

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


Re: Using OCX in console application 80 80

> 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?

See http://msdn.microsoft.com/en-us/library/aa751973%28v=vs.85%29.aspx

> 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' http://www.amazon.com/Inside-Microsoft-Programming-Dale-Rogerson/dp/1572313498

Then read Don Box http://www.amazon.com/Essential-COM-Don-Box/dp/0201634465/
and 'Understanding ActiveX and OLE' http://www.amazon.com/Understanding-ActiveX-OLE-Developers-Technology/dp/1572312165

Re: Using OCX in console application 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.