automaterobot.cpp

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

CPP
45
字号
// AutomateRobot.cpp 

#include "stdafx.h"
#include "AutomateRobot.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include "CRobot.h"

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	CoInitialize(NULL);
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
		nRetCode = 1;
	}
	else
	{
		CRobot r;
		if (r.CreateDispatch("RobotServer.Robot"))
		{
			r.put_BatteryLife(456);
			long bl = r.get_BatteryLife();
			char buf[32];
			wsprintf(buf, "BatteryLife = %d", bl);
			MessageBox(0, buf, "Msg", 0);

			r.Speak((BSTR)"Hello Automation");
		}

	}

	CoUninitialize();
	return nRetCode;
}

⌨️ 快捷键说明

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