本文整理汇总了C++中atl::CComPtr::Next方法的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr::Next方法的具体用法?C++ CComPtr::Next怎么用?C++ CComPtr::Next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atl::CComPtr
的用法示例。
在下文中一共展示了CComPtr::Next方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_clsid
void remote_host::get_clsid( const CATID& cat_id, LPCOLESTR server_name, CLSID& server_id )
{
DWPRINT( L"get_clsid( %s )\n", server_name );
CATID Implist[1] = { cat_id };
ATL::CComPtr<IEnumCLSID> iEnum;
HRESULT result = root_->EnumClassesOfCategories( 1, Implist, 0, NULL, &iEnum );
if (FAILED(result))
{
throw opc_exception( result, OLESTR("Failed to get enum for categeories") );
}
GUID glist;
ULONG actual;
while((result = iEnum->Next( 1, &glist, &actual )) == S_OK)
{
cotask_holder<OLECHAR> progID;
cotask_holder<OLECHAR> userType;
HRESULT res = root_->GetClassDetails( glist, progID.addr(), userType.addr() );
if(FAILED(res))
{
throw opc_exception( res, OLESTR("Failed to get ProgId from ClassId") );
}
else
{
DWPRINT( L"progId = %s\n", progID );
if ( lstrcmpW( progID.get(), server_name ) == 0 )
{
res = root_->CLSIDFromProgID( progID.get(), &server_id );
if ( FAILED(res) )
{
throw opc_exception( res, OLESTR("IOPCServerList::CLSIDFromProgID - Failed to get ClassId from ProgId") );
}
return;
}
}
}
}
示例2: get_clsid
//*
void local_host::get_clsid( const CATID& cat_id, LPCOLESTR server_name, CLSID& server_id )
{
#if defined _DEBUG && defined _CONSOLE
wprintf( L"get_clsid( %s )\n", server_name );
#endif
CATID Implist[1] = { cat_id };
ATL::CComPtr<IEnumCLSID> iEnum;
HRESULT result = root_->EnumClassesOfCategories(1, Implist,0, NULL, &iEnum);
if (FAILED(result))
{
throw opc_exception( result, OLESTR("Failed to get enum for categeories") );
}
GUID glist;
ULONG actual;
while((result = iEnum->Next(1, &glist, &actual)) == S_OK)
{
cotask_holder<OLECHAR> progID;
HRESULT res = ProgIDFromCLSID(glist, progID.addr());
if(FAILED(res))
{
throw opc_exception( res, OLESTR("Failed to get ProgId from ClassId") );
}
else
{
#if defined _DEBUG && defined _CONSOLE
wprintf( L"progId = %s\n", progID );
#endif
if ( lstrcmpW( progID.get(), server_name ) == 0 )
{
server_id = glist;
return;
}
}
}
}
示例3: UsingWMI
BOOL CEnumerateSerial::UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames)
#endif
{
//Make sure we clear out any elements which may already be in the array(s)
#if defined CENUMERATESERIAL_USE_STL
ports.clear();
friendlyNames.clear();
#else
ports.RemoveAll();
friendlyNames.RemoveAll();
#endif
//What will be the return value
BOOL bSuccess = FALSE;
//Create the WBEM locator
ATL::CComPtr<IWbemLocator> locator;
HRESULT hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&locator));
if (SUCCEEDED(hr))
{
ATL::CComPtr<IWbemServices> services;
hr = locator->ConnectServer(_bstr_t("\\\\.\\root\\cimv2"), NULL, NULL, NULL, 0, NULL, NULL, &services);
if (SUCCEEDED(hr))
{
//Execute the query
ATL::CComPtr<IEnumWbemClassObject> classObject;
hr = services->CreateInstanceEnum(_bstr_t("Win32_SerialPort"), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &classObject);
if (SUCCEEDED(hr))
{
bSuccess = TRUE;
//Now enumerate all the ports
hr = WBEM_S_NO_ERROR;
//Final Next will return WBEM_S_FALSE
while (hr == WBEM_S_NO_ERROR)
{
ULONG uReturned = 0;
ATL::CComPtr<IWbemClassObject> apObj[10];
hr = classObject->Next(WBEM_INFINITE, 10, reinterpret_cast<IWbemClassObject**>(apObj), &uReturned);
if (SUCCEEDED(hr))
{
for (ULONG n=0; n<uReturned; n++)
{
ATL::CComVariant varProperty1;
HRESULT hrGet = apObj[n]->Get(L"DeviceID", 0, &varProperty1, NULL, NULL);
if (SUCCEEDED(hrGet) && (varProperty1.vt == VT_BSTR) && (wcslen(varProperty1.bstrVal) > 3))
{
//If it looks like "COMX" then add it to the array which will be returned
if ((_wcsnicmp(varProperty1.bstrVal, L"COM", 3) == 0) && IsNumeric(&(varProperty1.bstrVal[3]), TRUE))
{
//Work out the port number
int nPort = _wtoi(&(varProperty1.bstrVal[3]));
#if defined CENUMERATESERIAL_USE_STL
ports.push_back(nPort);
#else
ports.Add(nPort);
#endif
//Also get the friendly name of the port
ATL::CComVariant varProperty2;
if (SUCCEEDED(apObj[n]->Get(L"Name", 0, &varProperty2, NULL, NULL)) && (varProperty2.vt == VT_BSTR))
{
#if defined CENUMERATESERIAL_USE_STL
#if defined _UNICODE
std::wstring szName(varProperty2.bstrVal);
#else
std::string szName(ATL::CW2A(varProperty2.bstrVal));
#endif
friendlyNames.push_back(szName);
#else
friendlyNames.Add(CString(varProperty2.bstrVal));
#endif
}
else
{
#if defined CENUMERATESERIAL_USE_STL
friendlyNames.push_back(_T(""));
#else
friendlyNames.Add(_T(""));
#endif
}
}
}
}
}
}
}
}
}
return bSuccess;
}