This example code creates a circle and places it in the 3D World. This example uses the IInformationTree5, IobjectManager51 and ITerrainRegularPolygon5 interfaces. To run this example, copy the code and place it in a C++ project.
When using the #import statement (as in this sample), it not only defines a smart pointer class for your interface using the COM_SMARTPTR_TYPEDEF() macro but it also creates a wrapper class that allows accessing properties such as
PITerraExplorer4->DisplayErrorMessages = FALSE.
Note: The smart pointer mechanism also releases the interface pointers, allowing the developer not to worry about them in the code. When you are not using this mechanism, do not forget to release the interfaces after you have finished using them.
#import "C:\Program Files\Skyline\TerraExplorer Pro\TerraExplorerX.dll" no_namespace, named_guids
ITerraExplorer4Ptr pITerraExplorer4;
IObjectManager51Ptr pIObjectManager51;
IInformationTree5Ptr pIInformationTree5;
try
{
// Creating the TerraExplorer CoClass
pITerraExplorer4.CreateInstance(CLSID_TerraExplorer);
// Get IObjectManager51 Interface
pITerraExplorer4.QueryInterface(IID_IObjectManager51,
(IObjectManager51Ptr**)&pIObjectManager51);
// Get IInformationTree5 Interface
pITerraExplorer4.QueryInterface(IID_IInformationTree5,
(IInformationTree5Ptr**)&pIInformationTree5);
// Prevent TerraExplorer from displaying the error messages.
PITerraExplorer4->DisplayErrorMessages = FALSE;
// Create a new group in the Information Tree under the root.
_bstr_t GroupName = "My Group";
_bstr_t Description = "My Circle";
long GroupID = pIInformationTree5->CreateGroup(GroupName, 0);
// Create a red circle at the coordinate 100,100 and altitude 5 meters
// above ground. The circle has a radius of 15 meters, has 16 segments and
// has a transparent green fill.
ITerrainRegularPolygon5* pICircle = NULL;
HRESULT hr = S_OK;
pICircle =pIObjectManager51->CreateCircle (100, 100, 5, 15, 16, RGB(255,0,0),
FT_TRANSPARENT, RGB(0,255,0), HSC_TERRAIN_RELATIVE,
GroupID, Description);
}
catch(_com_error const &e)
{
MessageBox(NULL, (char*)e.Description(), "Error", MB_OK);
return E_FAIL;
}