连接的源码
/*************************************************************************
* For Customer Support contact Analytical Graphics, Inc. at www.agi.com *
*************************************************************************/
#include "AgConnect.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
extern "C" {
const char* AgEAppName = _T("ConnectExample");
}
int main()
{
char* connection1 = NULL;
char* initFileName = NULL;
static const char connectName[256] = _T("localhost:5001");
AgTConReturnInfo returnInfo;
static char cmdString1[256] =
{ _T("Load / VDF \"{Your install location goes here}\\Data\\ExampleScenarios\\Intro_STK_Aircraft_Systems.vdf\"") };
static char cmdString2[256] = _T("AllAccess / ElimDups");
int i;
/* Initialize Connect */
AgConInit(initFileName);
/* Open a connection to STK */
AgConOpenSTK(&connection1, 0, connectName);
/* Set verbose and ack on */
AgConSetProperties(connection1, (AgCConVerboseOn | AgCConAckOn));
/* Begin sending IPC Commands */
AgConProcessSTKCmd(connection1, cmdString1, &returnInfo);
/*
* The first command, Load, returns no data, so no need
* to free memory allocated to returnInfo.
*/
AgConProcessSTKCmd(connection1, cmdString2, &returnInfo);
/* Finished sending commands, close the connection */
AgConCloseSTK(&connection1);
/* Print out the results of the AllAccess command */
for (i = 0; i < returnInfo.numEntries; i++)
{
AgUtMsg(AgCMsgForceInfo, AgCMsgNoWait, AgCMsgDispDefault, AgCMsgNoErrorCode,
AgCMSourceLine, _T("Return entry %d:\n%s\n"), i + 1, returnInfo.returnList[i]);
}
/* Clean up the Return Information, freeing any unneeded memory */
AgConCleanupReturnInfo(&returnInfo);
/* Free remaining allocated memory in the Connect module in
* preparation for exit
*/
AgConShutdownConnect();
std::cout << "Press enter to exit...\n";
std::cin.get();
return (0);
}
可能发生的问题:
1.如果AgCMSourceLine报错显示“TFILE无定义”,根据文件查找定义发现可能是字符unicode是或非的问题与项目属性发生冲突,那么检查项目文件的属性,然后将字符集改为无定义即可。
2.如果运行结果并没有连接上,则先启动STK即可。