template <class T>
class UniquePtr
{
public:
UniquePtr(const std::vector<std::string>& strOids)
:m_ptr(NULL),
m_isValid(false)
{
m_ptr = new SnmpVarBindList;
if(m_ptr == NULL)
{
return;
}
SnmpVarBindList* tmp = (SnmpVarBindList*)m_ptr;
// 给请求对象分配内存
tmp->len = strOids.size();
tmp->list = NULL;
tmp->list = (SnmpVarBind *)SNMP_malloc(sizeof(SnmpVarBind) * tmp->len);
if (NULL == tmp->list)
{
DWORD dwErrCode = GetLastError();
m_strErr.Format(_T("UniquePtr SNMP_malloc failed, GetLastError=%d"), dwErrCode);
return;
}
for(size_t i=0; i < strOids.size(); i++)
{
tmp->list[i].value.asnType = ASN_NULL;
if (!SnmpMgrStrToOid((LPSTR)strOids[i].c_str(), &(tmp->list[i].name)))
{
DWORD dwErrCode = GetLastError();
m_strErr.Format(LocalString(_T("UniquePtr 转换对象标识符字符串格式到内部对象标识符失败,GetLastError=%d")
自动释放内存模板(自动关闭等等)
最新推荐文章于 2023-02-15 22:48:42 发布