
#include <wchar.h>

#import "..\\..\\..\\Engine\\Bin\\CAO.exe"
using namespace CAOLib;

void Run();

void main()
{
	CoInitialize(0);

	Run();

	CoUninitialize();
}

void Run()
{
	HRESULT hr = S_OK;
	ICaoEnginePtr pIEng;
	ICaoWorkspacesPtr pIWss;
	ICaoWorkspacePtr pIWs;
	ICaoControllerPtr pICtrl;
	ICaoVariablePtr pIVar;

	// CaoEngineの生成
	try {
		hr = pIEng.CreateInstance(L"CAO.CaoEngine");

		// Workespaceコレクションの取得
		pIWss = pIEng->GetWorkspaces();

		// Workspaceの取得
		pIWs = pIWss->Item(_variant_t(0L));

		// Controllerの生成
		pICtrl = pIWs->AddController(_bstr_t(L"RC1"), _bstr_t(L"CaoProv.Dummy"), _bstr_t(L""), _bstr_t(L""));

		// Variableの生成
		pIVar = pICtrl->AddVariable(_bstr_t(L"S11"), _bstr_t(L""));

	}
	catch (_com_error e) {
		hr = e.Error();
		return;
	}

	// 値の設定
	try {
		wchar_t wcsBuf[256];
		wprintf(L"Input data : ");
#if _MSC_VER <  1400
		_getws(wcsBuf);
#else
		_getws_s(wcsBuf, sizeof(wcsBuf)/sizeof(wchar_t));
#endif
		pIVar->PutValue(_variant_t(wcsBuf));
	}
	catch (_com_error e) {
		wprintf(L"Failed CaoVariable::put_Value.");
		return;
	}

	// 値の取得
	try {
		_variant_t vntVal;
		vntVal = pIVar->GetValue();
		wprintf(L"Output data : %s\r\n", vntVal.bstrVal);
	}
	catch (_com_error e) {
		wprintf(L"Failed CaoVariable::get_Value.");
		return;
	}

	wprintf(L"Press any key.");
	getwchar();

}