importrobot.cpp

来自「Visual_C++[1].NET_Bible1 Visual_C++宝典书中」· C++ 代码 · 共 32 行

CPP
32
字号
// ImportRobot.cpp 

#include "stdafx.h"
#import "..\RobotServer\_RobotServer.tlb" \
        no_namespace named_guids

int _tmain(int argc, _TCHAR* argv[])
{
	CoInitialize(NULL);

	try
	{
		IRobotPtr p(CLSID_CRobot);

		p->PutBatteryLife(123);
		long bl = p->GetBatteryLife();
		char buf[32];
		wsprintf(buf, "BatteryLife = %d", bl);
		MessageBox(0, buf, "Msg", 0);

		p->Speak(L"Hello World");
	}
	catch(_com_error& e)
	{
		MessageBox(0, e.ErrorMessage(), 0, 0);
	}

	CoUninitialize();
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?