/// <summary> /// Returns one or more rows from a table, beginning at the current cursor position. /// </summary> /// <param name="lRowCount">Maximum number of rows to be returned.</param> /// <param name="sRows">an SRow array holding the table rows.</param> /// <returns></returns> public bool QueryRows(int lRowCount, out SRow[] sRows) { IntPtr pRowSet = IntPtr.Zero; HRESULT hr = tb_.QueryRows(lRowCount, 0, out pRowSet); if (hr != HRESULT.S_OK) { MAPINative.MAPIFreeBuffer(pRowSet); } uint cRows = (uint)Marshal.ReadInt32(pRowSet); sRows = new SRow[cRows]; if (cRows < 1) { MAPINative.MAPIFreeBuffer(pRowSet); return(false); } int pIntSize = IntPtr.Size, intSize = Marshal.SizeOf(typeof(Int32)); int sizeOfSRow = 2 * intSize + pIntSize; IntPtr rows = pRowSet + intSize; for (int i = 0; i < cRows; i++) { IntPtr pRowOffset = rows + i * sizeOfSRow; uint cValues = (uint)Marshal.ReadInt32(pRowOffset + pIntSize); IntPtr pProps = Marshal.ReadIntPtr(pRowOffset + pIntSize + intSize); IPropValue[] lpProps = new IPropValue[cValues]; for (int j = 0; j < cValues; j++) // each column { SPropValue lpProp = (SPropValue)Marshal.PtrToStructure(pProps + j * Marshal.SizeOf(typeof(SPropValue)), typeof(SPropValue)); lpProps[j] = new MAPIProp(lpProp); } sRows[i].propVals = lpProps; } MAPINative.MAPIFreeBuffer(pRowSet); return(true); }
/// <summary> /// Returns one or more rows from a table, beginning at the current cursor position. /// </summary> /// <param name="lRowCount">Maximum number of rows to be returned.</param> /// <param name="sRows">an SRow array holding the table rows.</param> /// <returns></returns> public bool QueryRows(int lRowCount, out SRow[] sRows) { IntPtr pRowSet = IntPtr.Zero; HRESULT hr = tb_.QueryRows(lRowCount, 0, out pRowSet); if (hr != HRESULT.S_OK) { MAPINative.MAPIFreeBuffer(pRowSet); } uint cRows = (uint)Marshal.ReadInt32(pRowSet); sRows = new SRow[cRows]; if (cRows < 1) { MAPINative.MAPIFreeBuffer(pRowSet); return false; } int pIntSize = IntPtr.Size, intSize = Marshal.SizeOf(typeof(Int32)); int sizeOfSRow = 2 * intSize + pIntSize; IntPtr rows = pRowSet + intSize; for (int i = 0; i < cRows; i++) { IntPtr pRowOffset = rows + i * sizeOfSRow; uint cValues = (uint)Marshal.ReadInt32(pRowOffset + pIntSize); IntPtr pProps = Marshal.ReadIntPtr(pRowOffset + pIntSize + intSize); IPropValue[] lpProps = new IPropValue[cValues]; for (int j = 0; j < cValues; j++) // each column { SPropValue lpProp = (SPropValue)Marshal.PtrToStructure(pProps + j * Marshal.SizeOf(typeof(SPropValue)), typeof(SPropValue)); lpProps[j] = new MAPIProp(lpProp); } sRows[i].propVals = lpProps; } MAPINative.MAPIFreeBuffer(pRowSet); return true; }