Getting started
This page demonstrates C++ development using the "#import" directive. When using the "#import" statement, it not only defines a smart pointer class for your interface using the COM_SMARTPTR_TYPEDEF() macro but also creates a wrapper class that allows accessing properties as
PITerraExplorer5->DisplayErrorMessages = FALSE.
Note: The smart pointer mechanism also releases the interface pointers, so developers don’t need to worry about them in the code. When not using this mechanism, remember to release the interfaces after you finish using them.
- Download and install TerraExplorer Plus.
- Create a new Win32 Console Application project in Visual Studio, using Visual C++.
- In Visual Studio, select File> New> Project.
- Select Visual C++ >Win32 >Win32 Console Application.
- Name the project TerraExplorerShowcase.
- Click OK and then click Finish.
- Add the "#import" statement after all the include statements to link your project to the TerraExplorer COM interface. Make sure the name of the file in this command points to the TerraExplorer or TerraExplorer Pro executable on your computer.
#import "C:\Program Files\Skyline\TerraExplorer\TerraExplorerX.dll" no_namespace, named_guids
- Initialize COM infrastructure inside your main method.
CoInitialize(NULL);
{
// Work with TerraExplorer here, using SGWorld class
}
CoUninitialize();
- Create the SGWorld CoClass.
Note: You must create a SGWorld CoClass before working with the
interfaces. The constant CLSID_SGWorld is automatically defined by the "#import" command.
ISGWorld6Ptr pISGWorld;
pISGWorld.CreateInstance(CLSID_SGWorld);
- Call the methods on the interface pointer.
pISGWorld->Project->Open("http://www.skylinesoft.com/SkylineGlobe/WebClient/PresentationLayer/WebClient/SkyglobeLB.fly",FALSE,"","");
IPosition6Ptr pIPosition6 = pISGWorld->Creator->CreatePosition(-77.036667, 38.895111, 1500,AltitudeTypeCode::ATC_TERRAIN_RELATIVE,0,0,0,0);
pISGWorld->Navigate->FlyTo(_variant_t(pIPosition6),ActionCode::AC_FLYTO);
- Full code for the example.
// TerraExplorerShowcase.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#import "c:\Program Files\Skyline\TerraExplorer\TerraExplorerX.dll" no_namespace, named_guids
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
{
try
{
ISGWorld6Ptr pISGWorld;
pISGWorld.CreateInstance(CLSID_SGWorld);
pISGWorld->Project->Open("http://www.skylinesoft.com/SkylineGlobe/WebClient/PresentationLayer/WebClient/SkyglobeLB.fly",FALSE,"","");
IPosition6Ptr pIPosition6 = pISGWorld->Creator->CreatePosition(-77.036667, 38.895111, 1500,AltitudeTypeCode::ATC_TERRAIN_RELATIVE,0,0,0,0);
pISGWorld->Navigate->FlyTo(_variant_t((IDispatch*)pIPosition6),ActionCode::AC_FLYTO);
}
catch( _com_error &e )
{
// Crack _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf( _T("Exception thrown for classes generated by #import") );
_tprintf( _T("\tCode = %08lx\n"), e.Error());
_tprintf( _T("\tCode meaning = %s\n"), e.ErrorMessage());
_tprintf( _T("\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf( _T("\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
}
CoUninitialize();
return 0;
}
Related Links & Files
|