tags:

views:

49

answers:

3

I have imported an ActiveX library into my project in Visual Studio 2008 using:

#import "TeeChart8.ocx" named_guids

Now I would like to create objects exposed by the ActiveX library. However, I am having trouble understanding the API.

There are two files that were created after I built the project with the #import, a .tli file and a .tlh file.

In the .tlh file there is the following line:

_COM_SMARTPTR_TYPEDEF(ITChart, __uuidof(ITChart));

I can see ITChart when I open the ActiveX library TeeChart8.ocx in the ITypeLib Viewer (Oleview). Also, if I type ITChartPtr->Invoke into my code, intellisense shows me that there are a whole bunch of parameters that need to be filled.

Essentially, I would like to know how to instantiate an ActiveX object and where I have to look to get the information I need?

+1  A: 

Look up the function CoCreateInstance in your API docs.

Anders K.
+2  A: 

Maybe not enough to create ActiveX function CoCreateInstance. ActiveX must be correctly initialized (Theory can be found here ActiveX Controls Overviews and Tutorials :-)

The easiest way is to use CAxWindow (ATL Framework)

Here, collected various information on how to create ActiveX controls

Victor
+1  A: 

When it's a simple COM object, you can use the following (assuming a coclass named TChart to go with the interface named ITChart):

ITChartPtr chart(__uuidof(TChart));

For more information on using the ITChartPtr type defined by the _COM_SMARTPTR_TYPEDEF macro in the .tlh file generated by the #import statement, see com_ptr_t.

If it's a full ActiveX control, there is more to it as Victor said in his answer.

GBegen
Yes there is a coclass named TChart. Are there additional includes I have to add apart from importing the .ocx file? As it is not building as it does not recognise ITChartPtr.
Seth
This worked with the help of this article http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/ab212d8a-d0f3-4d59-89c6-3051a4921470
Seth