public CoreResult[] GetResult(uint startFrom, uint size) { uint resultSize = GetResultSize(); if (resultSize > startFrom) { object resultObject = new CoreDll.adResultW(); int sizeOfResult = Marshal.SizeOf(resultObject); byte[] buffer = new byte[sizeOfResult * PAGE_SIZE]; size = Math.Min(resultSize - startFrom, size); CoreResult[] results = new CoreResult[size]; uint pageCount = (uint)(size / PAGE_SIZE + (size % PAGE_SIZE > 0 ? 1 : 0)); for (uint page = 0; page < pageCount; ++page) { UIntPtr[] pStartFrom = new UIntPtr[1]; pStartFrom[0] = new UIntPtr(startFrom + page * PAGE_SIZE); UIntPtr[] pSize = new UIntPtr[1]; pSize[0] = new UIntPtr(PAGE_SIZE); if (m_dll.adResultGetW(m_handle, Marshal.UnsafeAddrOfPinnedArrayElement(pStartFrom, 0), Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0), Marshal.UnsafeAddrOfPinnedArrayElement(pSize, 0)) == CoreDll.Error.Ok) { for (uint i = 0; i < pSize[0].ToUInt32(); ++i) { IntPtr pResult = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, (int)(i * sizeOfResult)); CoreDll.adResultW result = (CoreDll.adResultW)Marshal.PtrToStructure(pResult, resultObject.GetType()); results[page * PAGE_SIZE + i] = new CoreResult(ref result); } } } return(results); } return(null); }