1. 在函数体里面定义结构体
//获取枚举变量对应的字符串名称,可定义在函数体里面
CString GetProgressName(ConnectProgress status) const
{
struct ProgressInfo
{
ConnectProgress id;
TCHAR* text;
};
const ProgressInfo EventInfos[] =
{
{CONNECT_PROGRESS_UNKNOW, _T("未知")},
{CONNECT_PROGRESS_DRIVER, _T("整个连接的第一个步骤,安装驱动")},
{CONNECT_PROGRESS_CONNECT, _T("开始连接")},
{CONNECT_PROGRESS_DRIVERBEGIN, _T("正在安装手机驱动")},
{CONNECT_PROGRESS_FILTERBEGIN, _T("正在安装FILTER驱动")},
{CONNECT_PROGRESS_FILTERBEGIN_SAMSUNG, _T("正在安装三星FILTER驱动")},
{CONNECT_PROGRESS_DRIVER_WINPENDING_START, _T("WINDOWS安装驱动开始")},
{CONNECT_PROGRESS_DRIVER_WINPENDING_DRIVER, _T("WINDOWS正在驱动")},
{CONNECT_PROGRESS_DRIVER_WINPENDING_FILTER, _T("WINDOWS正在FILTER驱动")},
{CONNECT_PROGRESS_SUCCESS, _T("连接成功")},
};
const int counts = sizeof(EventInfos) / sizeof(EventInfos[0]);
if (status < 0 || status >= counts)
{
ATLASSERT(FALSE);
return _T("Error");
}
return EventInfos[status].text;
}
2.名字空间宏定义字符串
namespace APKPackageInfo
{
const BSTR PACKAGE_ARRAY = L"Array";
const BSTR BSTR_PACKAGE_NAME = L"PackName";
const BSTR BSTR_VERSION_NAME = L"Version";
const BSTR INT_VERSION_CODE = L"VersionCode";
const BSTR BSTR_INSTALL_DATE = L"date";
const BSTR BOOL_SYSTEM = L"system";
const BSTR BSTR_INSTALL_PATH = L"path";
}