public SPropValue(pSPropValue prop) { this.tag = (PropTags)prop.ulPropTag; switch ((PT)((uint)this.tag & 0xFFFF)) { case PT.PT_TSTRING: this.t = typeof(string); this.str = Marshal.PtrToStringUni(prop.Value.lpszW); break; case PT.PT_LONG: case PT.PT_I2: case PT.PT_BOOLEAN: this.t = typeof(int); this.ul = prop.Value.ul; break; case PT.PT_BINARY: this.t = typeof(SBinary); this.binary = prop.Value.bin.AsBytes; break; case PT.PT_SYSTIME: case PT.PT_I8: this.t = typeof(UInt64); this.p_li = prop.Value.li; break; default: this.t = null; break; } }
public bool SetProps(PropTags[] tags, object[] values) { int num = tags.Length; if (num != values.Length) throw new Exception("Num tags must be same as num of values!!"); IntPtr array = Marshal.AllocHGlobal(cemapi.SizeOfSPropValue * num); for (int i = 0; i < num; i++) { PropTags tag = tags[i]; object value = values[i]; pSPropValue val = new pSPropValue(); val.ulPropTag = (uint)tag; switch ((PT)((uint)tag & 0xFFFF)) { case PT.PT_BINARY: case PT.PT_TSTRING: throw new Exception("Can't set property " + tag.ToString() + '!'); case PT.PT_BOOLEAN: val.Value.li = (bool)value ? 1UL : 0UL; break; case PT.PT_SYSTIME: case PT.PT_I8: val.Value.li = (ulong)value; break; case PT.PT_I2: val.Value.li = (ulong)((short)value); break; case PT.PT_LONG: val.Value.li = (ulong)((uint)value); break; default: throw new Exception("Can't set property " + tag.ToString() + '!'); } Marshal.StructureToPtr(val, (IntPtr)((uint)array + cemapi.SizeOfSPropValue * i), false); } HRESULT hr = pIMAPIPropSetProps(this.ptr, (uint)num, array); Marshal.FreeHGlobal(array); if (hr == HRESULT.S_OK) return true; else if (hr == HRESULT.MAPI_E_COMPUTED) return false; else throw new Exception("SetProps failed: " + hr.ToString()); }