// DevicesEnum.cpp : Implementation of CDevCon2App and DLL registration. #include "stdafx.h" #include "DevCon2.h" #include "Device.h" #include "Devices.h" #include "DevicesEnum.h" ///////////////////////////////////////////////////////////////////////////// // CDevicesEnum::~CDevicesEnum() { DWORD c; if(pDevices) { for(c=0;cRelease(); } delete [] pDevices; } } HRESULT CDevicesEnum::Next( ULONG celt, VARIANT * rgVar, ULONG * pCeltFetched ) { ULONG fetched; CDevice *pDev; if(pCeltFetched) { *pCeltFetched = 0; } for(fetched = 0; fetchedAddRef(); V_VT(&rgVar[fetched]) = VT_DISPATCH; V_DISPATCH(&rgVar[fetched]) = pDev; } if(pCeltFetched) { *pCeltFetched = fetched; } return (fetched *pEnum = NULL; hr = CComObject::CreateInstance(&pEnum); if(FAILED(hr)) { return hr; } if(!pEnum) { return E_OUTOFMEMORY; } if(!pEnum->CopyDevices(pDevices,Count)) { delete pEnum; return E_OUTOFMEMORY; } pEnum->Position = Position; pEnum->AddRef(); *ppEnum = pEnum; return S_OK; } BOOL CDevicesEnum::CopyDevices(CDevice **pArray, DWORD NewCount) { DWORD c; if(pDevices) { delete [] pDevices; pDevices = NULL; } Count = 0; Position = 0; pDevices = new CDevice*[NewCount]; if(!pDevices) { return FALSE; } for(c=0;cAddRef(); pDevices[c] = pArray[c]; if(!pDevices[c]) { Count = c; return FALSE; } } Count = NewCount; return TRUE; }