Instantiating an ActiveX Object
I have imported an ActiveX library into my project in Visual Studio 2008 us开发者_如何学JAVAing:
#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?
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
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.
Look up the function CoCreateInstance in your API docs.
精彩评论